From: John H. on 4 Mar 2010 15:54 On Mar 4, 1:09 pm, "Peter Olcott" <NoS...(a)OCR4Screen.com> wrote: > Do you think that it could copy from 32-bit to 8-bit > indexed? I think so. Below is an example. With some thinking, you might be able to figure out a way to work directly with the pixel bits (via CImage::GetBits) that can do things faster. #include "stdafx.h" #include <atlimage.h> #include <set> int main() { // Load the source image: CImage img24; img24.Load("256colors.bmp"); // Gather all the colors in the image: std::set<COLORREF> colors; for(int i=0; i<img24.GetHeight(); ++i) { for(int j=0; j<img24.GetWidth(); ++j) { colors.insert(img24.GetPixel(j,i)); } } // Make a color table holding the colors: RGBQUAD table[256]; std::set<COLORREF>::const_iterator color = colors.begin(); for(int index=0; index<256; ++index) { table[index].rgbBlue = GetBValue(*color); table[index].rgbGreen = GetGValue(*color); table[index].rgbRed = GetRValue(*color); table[index].rgbReserved = 0; ++color; } // Make the destination image: CImage img8; img8.Create(img24.GetWidth(), img24.GetHeight(), 8); img8.SetColorTable(0, 256, table); // Copy the pixels: HDC const hdc = img8.GetDC(); img24.BitBlt(hdc, 0, 0); img8.ReleaseDC(); img8.Save("8bpp.bmp"); return 0; }
First
|
Prev
|
Pages: 1 2 Prev: Square shaped balloon tips. Next: Add line numbering on crichedit control |