将图像绘制到图元文件时出现意外的GDI +错误 [英] Unexpected GDI+ error when draw image to metafile

查看:49
本文介绍了将图像绘制到图元文件时出现意外的GDI +错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题:

我必须使用某些图像属性将图像绘制到图元文件中.如果从流创建图像,则会收到意外的GDI +错误内存不足".如果从文件创建图像,则效果很好.

I have to draw image into metafile using certain image attributes.If Image is created from stream I receive unexpected GDI+ error "Out of memory". If Image is created from file it works fine.

你能帮我吗?

最诚挚的问候,阿列克谢

Best regards, Alexey

示例源代码如下:

Graphicsgraph  = null;

IntPtrhdc = newIntPtr(0);

SizeaSize = newSize(1190,842);

GraphicsrefGraph  = Graphics.FromHwnd(newIntPtr());

try{

hdc = refGraph.GetHdc();

hdc = refGraph.GetHdc();

Rectanglerect = newRectangle(0, 0, aSize.Width, aSize.Height);

MetafileaMetafileImage = newMetafile(hdc, rect, MetafileFrameUnit.Pixel, EmfType.EmfOnly);

graph =

Graphics.FromImage(aMetafileImage);

RectangleaTestRect = newRectangle(0, 0, 267, 267);

ImageaTestImage = null;

",

using( FileStreamaStream = newFileStream("testImage.png", FileMode.Open) ) {

aTestImage =

aTestImage =

Image.FromStream(aStream);

}

floatreducedOpacity = 0.5f;

float[][] matrixItems ={

浮动 [] {1,0,0,0,0},

newfloat[] {1, 0, 0, 0, 0},

浮动 [] {0,1,0,0,0},

newfloat[] {0, 1, 0, 0, 0},

浮动 [] {0,0,1,0,0},

newfloat[] {0, 0, 1, 0, 0},

浮动 [] {0,0,0,1,0},

newfloat[] {0, 0, 0, 1, 0},

浮动 [] {0,0,0,0,1}};

newfloat[] {0, 0, 0, 0, 1}};

ColorMatrixcm = newColorMatrix(matrixItems);

cm.Matrix33 =(

cm.Matrix33 = (

ImageAttributesia = newImageAttributes();

ia.SetColorMatrix(cm,

ia.SetColorMatrix(cm,

ColorMatrixFlag.Default, ColorAdjustType.Default);

graph.DrawImage(aTestImage,aTestRect,0,0,aTestImage.Width,aTestImage.Height,

graph.DrawImage(aTestImage, aTestRect, 0, 0, aTestImage.Width, aTestImage.Height,

GraphicsUnit.Pixel, ia);

ia.Dispose();

ia.Dispose();

}

finally{

refGraph.ReleaseHdc(hdc);

refGraph.ReleaseHdc(hdc);

refGraph.Dispose();

refGraph.Dispose();

if( graph != null)

graph.Dispose();

graph.Dispose();

}

推荐答案

在整个绘制期间尝试保持 aStream 打开,即扩大使用...  {}"块.

Try keeping the aStream open during the whole drawing period, i.e. enlarge the "using ... { }" block.


这篇关于将图像绘制到图元文件时出现意外的GDI +错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆