Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 字节[]到XImage失败,使用通用GDI+;错误_.net_Image_Gdi+_Pdfsharp - Fatal编程技术网

.net 字节[]到XImage失败,使用通用GDI+;错误

.net 字节[]到XImage失败,使用通用GDI+;错误,.net,image,gdi+,pdfsharp,.net,Image,Gdi+,Pdfsharp,我正在使用PDFsharp在PDF中插入图像。图像以二进制对象的形式来自数据库。要使用PDFsharp插入它,我需要将其作为XImage。以下是我目前正在尝试的: XImage sealXImage; using (var ms = new MemoryStream(seal.SealerImage)) // seal.SealerImage is the byte[], I verified this does actually have data in it { Image seal

我正在使用PDFsharp在PDF中插入图像。图像以二进制对象的形式来自数据库。要使用PDFsharp插入它,我需要将其作为XImage。以下是我目前正在尝试的:

XImage sealXImage;
using (var ms = new MemoryStream(seal.SealerImage))
// seal.SealerImage is the byte[], I verified this does actually have data in it
{
    Image sealImage = Image.FromStream(ms);
    sealXImage = XImage.FromGdiPlusImage(sealImage);
}
 XGraphics gfx = XGraphics.FromPdfPage(pdfToSeal.Pages[pageNumber]);
 gfx.DrawImage(sealXImage, 425, 475, 150, 100); // generic GDI+ error on this line
因此,它一直愉快地工作到最后一行,其中抛出了一个GDI+错误:

System.Runtime.InteropServices.ExternalException:GDI+中发生一般错误


我做错了什么?我能做些什么来解决这个问题?提前感谢。

我怀疑问题在于使用的
:调用
DrawImage()
时,内存流不再存在。如果我是正确的,使用
块在
内调用DrawImage应该可以解决这个问题


您也可以调用
XImage.FromStream()
,但我认为如果不使用
范围更改
,您也会遇到同样的问题。

花了一个多小时的时间在谷歌上搜索并试图找到这个问题,而这正是我遇到的问题。