我正在尝试将多个图像转换为多 tiff 图像文件。当我在多个图像上运行以下代码时,我收到“GDI+ 中发生一般错误”。错误。如果我只有一张图像,那么它可以正常工作并输出文件。如果我将代码更改为位图并将列表更改为位图,则该代码适用于多个图像。
public List<Metafile> metaFileList = new List<Metafile>();
private void writeImagesToEnhancedMetaMulTiff()
{
ImageCodecInfo info = null;
foreach (ImageCodecInfo ice in ImageCodecInfo.GetImageEncoders())
if (ice.MimeType == "image/tiff")
info = ice;
System.Drawing.Imaging.Encoder enc = System.Drawing.Imaging.Encoder.SaveFlag;
EncoderParameters ep = new EncoderParameters(1);
ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.MultiFrame);
Metafile pages = null;
int frames = 0;
foreach (Metafile metaFileItem in metaFileList)
{
if (frames == 0)
{
pages = metaFileItem;
pages.Save(@"E:\output_MetaFile.tif", info, ep);
}
else
{
ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.FrameDimensionPage);
pages.SaveAdd(metaFileItem, ep);
}
if (frames >= metaFileList.Count() - 1)
{
ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.Flush);
}
frames++;
}
}
要访问获取剪贴板作为元文件,我一直在使用以下代码:
public System.Drawing.Imaging.Metafile GetEnhMetafileOnClipboard(IntPtr hWnd)
{
System.Drawing.Imaging.Metafile meta = null;
if(OpenClipboard(hWnd))
{
try
{
if (IsClipboardFormatAvailable(CF_ENHMETAFILE) != 0)
{
IntPtr hmeta = GetClipboardData(CF_ENHMETAFILE);
meta = new System.Drawing.Imaging.Metafile(hmeta, true);
metaFileList.Add(meta);
}
}
finally
{
CloseClipboard();
}
}
return meta;
}
如果您需要我提供更多代码,请告诉我。
谢谢。