开发者

Creating a Dib by only specifying the size with GDI+ and DotNet

开发者 https://www.devze.com 2022-12-18 02:30 出处:网络
I have just recently discovered the difference between different constructors in GDI+.Going: var bmp = new Bitmap(width, height, pixelFormat);

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开发者_如何学Go. 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号