Can any one let me know how to save 开发者_运维技巧1BPP , 4BPP and 8BPP as Bitmap. I have bits in the image, width and height.
Please let me know how to save that as bitmap.
For Windows and C++, the easiest way is Gdiplus. Here's some pseudo code.
Gdiplus::Bitmap* pBmp = new Gdiplus::Bitmap(width, height, pixelformat);
pBmp->SetPalette(...); // initialize palette for 8bpp formats and less
pBmp->LockBits(...); // acquire the bitmap buffer
// copy your binary image data into the buffer
pBmp->UnlockBits(...); // return the buffer
pBmp->Save(filename, &clsidBMP, NULL);
delete pBmp;
You can get a list of pixel formats defined by GDI plus here.
Most of what you need is defined by the Bitmap class, which inherits from the Image class, which defines the Save method.
The encoder clsid, required by the "save" method is a bit tricky to get. But see my posting here on how to acquire this value.
ATL::CImage* image_ = new CImage();
image_ -> Create( rect.right - rect.left, rect.bottom - rect.top, 32 );
...
image_ -> Save( filename );
delete image_;
Change to parameter in Create() appropriately.
精彩评论