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

孤者浪人 提交于 2020-01-04 05:42:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!