Hello Everyone,
i am new to VC++,
i am doing a simple vc++ project in that i had a situation.
scenario is...
i have images in .jpeg,.bmp and .png.
i need to implement an algorithm for image compression.....
Steps are:
• Load image into 24-bit image buffer
• Locate top, left pixel
• Convert Red channel 8-bit value to 6-bit
o 6-bit = (8-bit_RedValue/255) * 63
o Round computed 6-bit value to nearest integer
o Multiply rounded value by 4 (left shift by 2 bits) to shift 6-bit value into upper 6 bits of a byte
o Store resulting 8-bit value into the Red channel of the final output file
• Repeat conversion for Green channel
• Repeat conversion for Blue channel
• Move to pixel located directly to the right. If at the end of the line, move to the left-most pixel of the next line. Repeat until all pixels have been processed
and my code is:
Bitmap^ img=gcnew Bitmap(b1->Size.Width,b1->Size.Height, PixelFormat::Format24bppRgb);
img->SetResolution(b1->HorizontalResolution, b1->VerticalResolution);
Graphics^ g=Graphics::FromImage(img);
g->DrawImage(b1,0,0);
delete g;
Color c;
for (int i = 0; i < img->Width; i++)
{
for (int j = 0; j < img->Height; j++)
{
c = img->GetPixel(i, j);
double oldr = c.R;
double oldg = c.G;
double oldb = c.B;
int r=Math::Round((oldr/255)*63);
int g=Math::Round((oldg/255)*63);
int b=Math::Round((oldb/255)*63);
int R=System::Convert::ToInt32(r*4);
int G=System::Convert::ToInt32(g*4);
int B=System::Convert::ToInt32(b*4);
img->SetPixel(i,j,Color::FromArgb(R,G,B));
}
}
here after saving the final image..... the final image is taking high memory to save ...
like original image =10kb
final image=100kb...
please help me doing this........