if (isEightBit)
{
imagePtr->Create(pdib->biWidth,pdib->biHeight, 8);
unsigned char * pImgBits= (unsigned char*)imagePtr->GetBits();
int iPitch = imagePtr->GetPitch();
char *pbitThat;
int iCount=0;
int iMultBitCountFactor = pdib->biBitCount/8;
int iMultBitCountFactor8 = pdib->biBitCount/32;
////TO OPTIMIZE
for ( int y=0; ybiHeight; y++ )
{
for ( int x=0; xbiWidth; x++ )
{
pbitThat = (char *) (LPBYTE(pImgBits) + (y * iPitch ) + x*iMultBitCountFactor8+0);
*pbitThat = imgBits [(pdib->biHeight-y-1)*pdib->biWidth*iMultBitCountFactor+x*iMultBitCountFactor+0];
pbitThat = (char *) (LPBYTE(pImgBits) + (y * iPitch ) + x*iMultBitCountFactor8+1);
*pbitThat = imgBits [(pdib->biHeight-y-1)*pdib->biWidth*iMultBitCountFactor+x*iMultBitCountFactor+1];
pbitThat = (char *) (LPBYTE(pImgBits) + (y * iPitch ) + x*iMultBitCountFactor8+2);
*pbitThat = imgBits [(pdib->biHeight-y-1)*pdib->biWidth*iMultBitCountFactor+x*iMultBitCountFactor+2];
}
}
RGBQUAD clrs[256];
//set up a gray-scale palette
for(int i=0;i<256;i++){
clrs[i].rgbRed=i;
clrs[i].rgbGreen=i;
clrs[i].rgbBlue=i;
}
imagePtr->SetColorTable(0,256,clrs);
}
///////////////////////////////////this is the save code
result = imgPtr->Save("C:\\test_JPEG.jpg", Gdiplus::ImageFormatJPEG); //this is 24 bit depth
result = imgPtr->Save("C:\\test_BMP.jpg", Gdiplus::ImageFormatBMP); //this is 8 bit depth
result = imgPtr->Save("C:\\test_PNG.jpg", Gdiplus::ImageFormatPNG); //this is 8 bit depth
|