问题
I have just recently discovered the difference between different constructors in GDI+. Going:
var bmp = new Bitmap(width, height, pixelFormat);
creates a DDB (Device Dependent Bitmap) whereas:
var bmp = new Bitmap(someFile);
creates a DIB (Device Independent Bitmap). This is really not usually important, except when handling very large images (where a DDB will run out of memory, and run out of memory at different sizes depending on the machine and its video memory). I need to create a DIB rather than DDB, but specify the height, width and pixelformat. Does anyone know how to do this in DotNet. Also is there a guide to what type of Bitmap (DIB or DDB) is being created by which Bitmap constructor?
回答1:
It appears the best way to do this is to allocate the memory yourself, and then then create the bitmap with:
var bmp = new Bitmap(width, height, stride, format, scan0)
This way you can create huge bitmaps without having an out of memory error.
来源:https://stackoverflow.com/questions/2149483/creating-a-dib-by-only-specifying-the-size-with-gdi-and-dotnet