开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜