Simonhaner
asked on
codes for convert 16/24/32 bit bitmap to 256 color
Hi ,
I want to convert 16/24/32 bit bitmap to 256 color or grayscale . If anyone can give me a piece of code or address the forum ?
Thanks & Best Regards !
I want to convert 16/24/32 bit bitmap to 256 color or grayscale . If anyone can give me a piece of code or address the forum ?
Thanks & Best Regards !
check www.codeguru.com
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi ,
thanks for your help .
I've wrote a piece of code but the right of image was move to the left in most photo apps( if i open the saved image , ms painter can display it correctly while others can not)
i paste the codes here and hope u can give me a hand .
in the follow codes "buffer" is an array contains grayed pixel .
BITMAPINFO bmpInfo2;
bmpInfo2.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo2.bmiHeader.biWidth = 800;
bmpInfo2.bmiHeader.biHeigh t = 600;
bmpInfo2.bmiHeader.biPlane s = 1;
bmpInfo2.bmiHeader.biBitCo unt = 8;
bmpInfo2.bmiHeader.biCompr ession = BI_RGB;
bmpInfo2.bmiHeader.biXPels PerMeter = 0;
bmpInfo2.bmiHeader.biYPels PerMeter = 0;
bmpInfo2.bmiHeader.biClrUs ed = 256;
bmpInfo2.bmiHeader.biClrIm portant = 0;
bmpInfo2.bmiHeader.biSizeI mage = 800*600 ;
RGBQUAD pal[256] ;
for(int a =0 ;a < 256; a++ )
{
pal[a].rgbBlue = pal[a].rgbGreen=pal[a].rgb Red = a ;
pal[a].rgbReserved = 0 ;
}
CFile file ;
file.Open ("c:\\bmp",CFile::modeCrea te | CFile::modeWrite,NULL);
// z is begin with "BM8" z[4] = 0x24 z[10] = 0x36;
file.Write(z,14);
file.Write((char*)&bmpInfo 2,sizeof(B ITMAPINFO) -4);
file.Write((char*)pal,size of(RGBQUAD )*256);
file.Write((char*)buffer,8 00*600);
file.Close();
Thanks & b.Regards !
thanks for your help .
I've wrote a piece of code but the right of image was move to the left in most photo apps( if i open the saved image , ms painter can display it correctly while others can not)
i paste the codes here and hope u can give me a hand .
in the follow codes "buffer" is an array contains grayed pixel .
BITMAPINFO bmpInfo2;
bmpInfo2.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo2.bmiHeader.biWidth
bmpInfo2.bmiHeader.biHeigh
bmpInfo2.bmiHeader.biPlane
bmpInfo2.bmiHeader.biBitCo
bmpInfo2.bmiHeader.biCompr
bmpInfo2.bmiHeader.biXPels
bmpInfo2.bmiHeader.biYPels
bmpInfo2.bmiHeader.biClrUs
bmpInfo2.bmiHeader.biClrIm
bmpInfo2.bmiHeader.biSizeI
RGBQUAD pal[256] ;
for(int a =0 ;a < 256; a++ )
{
pal[a].rgbBlue = pal[a].rgbGreen=pal[a].rgb
pal[a].rgbReserved = 0 ;
}
CFile file ;
file.Open ("c:\\bmp",CFile::modeCrea
// z is begin with "BM8" z[4] = 0x24 z[10] = 0x36;
file.Write(z,14);
file.Write((char*)&bmpInfo
file.Write((char*)pal,size
file.Write((char*)buffer,8
file.Close();
Thanks & b.Regards !
ASKER
Hi ,
it's strange after i modify some codes the image is ok now
but anyone can tell me why ?
char z[14];
ZeroMemory(z,14);
strcpy(z,"BM");
z[3] = 0x36;
z[4] = 0x57;
z[10] = 0x36;
z[11] = 0x4 ;
.........
thanks !
it's strange after i modify some codes the image is ok now
but anyone can tell me why ?
char z[14];
ZeroMemory(z,14);
strcpy(z,"BM");
z[3] = 0x36;
z[4] = 0x57;
z[10] = 0x36;
z[11] = 0x4 ;
.........
thanks !
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity, I will suggest to accept "lyonst" comment(s) as an answer.
If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: https://www.experts-exchange.com/commspt
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: https://www.experts-exchange.com/commspt
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
Per recommendation, force-accepted by
Netminder
CS Moderator
Netminder
CS Moderator