English 中文(简体)
系统. Drawing。 图像。 Save sediments 外观: GDI 发生的一般错误
原标题:System.Drawing.Image.Save throws ExternalException: A generic error occurred in GDI

我的职能是绘制一份标本,其中一部分是用纸张,将其节省为8bpp。 结果图像的档案名称是独一无二的,档案确实存在,节目允许向目标夹书写。

void CropImage(Bitmap map) {
        Bitmap croped = new Bitmap(200, 50);

        using (Graphics g = Graphics.FromImage(croped)) {
            g.DrawImage(map, new Rectangle(0, 0, 200, 50), ...);
        }

        var encoderParams = new EncoderParameters(2);
        encoderParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 8L);
        encoderParams.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionNone);

        croped.Save(filename, tiffEncoder, encoderParams);
        croped.Dispose();
    }

更糟糕的是,这种幻觉在某些计算机(Win 7)和扔 throw系统上运行良好。 在其他计算机(主要是Win XP)的GDI例外中,出现了一般性错误。

所有计算机都安装了3.5 SP1运行时间。

如果我使用<代码>。 Save(档案名称,图像格式)。 传真:改为croped。 Save (filename, tiffEncoder, encoderParams); than it work on all Computer, but I need to Save Tiff in 8bpp form.

你们是否有任何想法,问题在哪里?

感谢卢卡斯

问题回答

GDI是一个窗口操作系统的功能。 我在处理16个借方的森林论坛档案时遇到了类似的问题,并求助于不同的图书馆。 见。 c#

MSDN帮助表明,这一功能是可用的,但在Windows,如果你试图将比图复制成新的比图,或将其保存到档案或流中,则会带来一般性的错误例外。 事实上,同一功能在Windows7上运行良好(似乎得到了森林论坛的良好支持)。 见New WIC functioanity inWindows 7

我所用的另一种解决办法是,在8个轨道上填写一份不安全的副本。 这样,我就能够拯救巴布亚新几内亚的档案(有棕榈笔)。 我没有为政府间森林论坛努力这样做。

       // part of a function taking a proprietary TIFF tile structure as input and saving it into the desired bitmap format
      // tile.buf is a byterarray, containing 16-bit samples from TIFF.

        bmp = new Bitmap(_tile_width, _tile_height, PixelFormat.Format8bppIndexed);
        System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height);
        BitmapData bmpData =bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,bmp.PixelFormat);
        int bytes = bmpData.Stride * bmp.Height;

        dstBitsPalette = (byte *)bmpData.Scan0;

        offset=0;


        for (offset = 0; offset < _tile_size; offset += 2)
        {
             dstBitsPalette[offset >> 1] = tile.buf[offset + 1];
        }

        // setup grayscale palette
        ColorPalette palette = bmp.Palette;
        for (int i = 0; i < 256; i++)
        {
            Color c = Color.FromArgb(i, i, i);
            palette.Entries[i] = c;
        }
        bmp.Palette = palette;
        bmp.UnlockBits(bmpData);

        return bmp;

    }




相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签