Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.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
C# 图元文件到多Tiff图像_C#_.net - Fatal编程技术网

C# 图元文件到多Tiff图像

C# 图元文件到多Tiff图像,c#,.net,C#,.net,我正在尝试将多个图像转换为多tiff图像文件。当我在多个映像上运行下面的代码时,我会得到一个“GDI+中发生一般错误”错误。如果我只有一个图像,那么它工作正常并输出文件。如果我将代码更改为位图,将列表更改为位图,那么代码可以很好地处理多个图像 public List<Metafile> metaFileList = new List<Metafile>(); private void writeImagesToEnhancedMetaMulTiff() {

我正在尝试将多个图像转换为多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++;
        }
    }
如果需要我提供更多代码,请告诉我


谢谢。

当我想要光栅化图元文件时,我一直避免使用图元文件的保存方法。相反,我将其绘制为位图,然后转换并保存位图

比如:

                    GraphicsUnit uPix = GraphicsUnit.Pixel;

                    RectangleF bounds = meta.GetBounds(ref uPix);
                    Bitmap dstBitmap = new Bitmap((int)bounds.Width, (int)bounds.Height, PixelFormat.Format32bppArgb);


                    Graphics g = Graphics.FromImage(dstBitmap);
                    g.Clear(Color.White);
                    g.DrawImage(meta, dstBitmap.GetBounds(ref uPix), meta.GetBounds(ref uPix), uPix);

                    dstBitmap.Save(@"E:\output_MetaFile.tif",info,ep);
从剪贴板获取图元文件时,我通常使用以下代码,因为在图元文件的情况下,从剪贴板复制数据非常重要:

if(iData.GetDataPresent(DataFormats.EnhancedMetafile))
        {

            // Get the meta data from the clipboard
            IntPtr hwnd = this.Handle;
            if(OpenClipboard(hwnd) == false) return false;
            IntPtr hToTempPastedEmf = GetClipboardData(14); //CF_ENHMETAFILE=14

            // Get the size of the meta data
            int iSize = GetEnhMetaFileBits(hToTempPastedEmf,0,IntPtr.Zero);                             
            // Copy the meta file from the clipboard (MUST remove all references to the clipboard)
            IntPtr hToPastedEmf = CopyEnhMetaFile(hToTempPastedEmf, new IntPtr(0));
            Metafile meta = new Metafile(hToPastedEmf,false); 

            CloseClipboard();

        }
if(iData.GetDataPresent(DataFormats.EnhancedMetafile))
        {

            // Get the meta data from the clipboard
            IntPtr hwnd = this.Handle;
            if(OpenClipboard(hwnd) == false) return false;
            IntPtr hToTempPastedEmf = GetClipboardData(14); //CF_ENHMETAFILE=14

            // Get the size of the meta data
            int iSize = GetEnhMetaFileBits(hToTempPastedEmf,0,IntPtr.Zero);                             
            // Copy the meta file from the clipboard (MUST remove all references to the clipboard)
            IntPtr hToPastedEmf = CopyEnhMetaFile(hToTempPastedEmf, new IntPtr(0));
            Metafile meta = new Metafile(hToPastedEmf,false); 

            CloseClipboard();

        }