GDI+ System.Drawing.Bitmap gives error Parameter is not valid intermittently

前端 未结 6 698
抹茶落季
抹茶落季 2021-02-05 16:23

I have some C# code in an ASP.Net application that does this:

Bitmap bmp = new Bitmap(1184, 1900);

And occasionally it throws an exception \"Parameter is not val

6条回答
  •  Happy的楠姐
    2021-02-05 16:46

    Stop using GDI+ and start using the WPF Imaging classes (.NET 3.0). These are a major cleanup of the GDI+ classes and tuned for performance. Additionally, it sets up a "bitmap chain" that allows you to easily perform multiple actions on the bitmap in an efficient manner.

    Find more by reading about BitmapSource

    Here's an example of starting with a blank bitmap just waiting to receive some pixels:

    using System.Windows.Media.Imaging;
    class Program {
        public static void Main(string[] args) {
            var bmp = new WriteableBitmap(1184, 1900, 96.0, 96.0, PixelFormat.Bgr32, null);
        }
    }
    

提交回复
热议问题