.net 字节[]到XImage失败,使用通用GDI+;错误
我正在使用PDFsharp在PDF中插入图像。图像以二进制对象的形式来自数据库。要使用PDFsharp插入它,我需要将其作为XImage。以下是我目前正在尝试的:.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
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()
,但我认为如果不使用范围更改,您也会遇到同样的问题。花了一个多小时的时间在谷歌上搜索并试图找到这个问题,而这正是我遇到的问题。