I have wrote a function to rotate a pf8bit bitmap.
It works fine for first rotation. When I rotate the bitmap again, the bitmap has changed and the color is different.
What's wrong and how can I correct this.
Thanks.
void __fastcall TForm2::Button2Click(TObject *Sender)
{
Graphics::TBitmap *bmp;
int h,w,i,j;
Byte *in,*out;
h=img->Picture->Bitmap->Height;
w=img->Picture->Bitmap->Width;
bmp=new Graphics::TBitmap;
bmp->Height=w;
bmp->Width=h;
bmp->PixelFormat=img->Picture->Bitmap->PixelFormat;
bmp->Palette=img->Picture->Bitmap->Palette;
for(i=0;i<h;i++)
{
in=(Byte *)img->Picture->Bitmap->ScanLine;
for(j=0;j<w;j++)
{
out=(Byte *)bmp->ScanLine[j];
out[h-1-i]=in[j];
}
}
img->Picture->Bitmap->Assign(bmp);
delete bmp;
}
It works fine for first rotation. When I rotate the bitmap again, the bitmap has changed and the color is different.
What's wrong and how can I correct this.
Thanks.
void __fastcall TForm2::Button2Click(TObject *Sender)
{
Graphics::TBitmap *bmp;
int h,w,i,j;
Byte *in,*out;
h=img->Picture->Bitmap->Height;
w=img->Picture->Bitmap->Width;
bmp=new Graphics::TBitmap;
bmp->Height=w;
bmp->Width=h;
bmp->PixelFormat=img->Picture->Bitmap->PixelFormat;
bmp->Palette=img->Picture->Bitmap->Palette;
for(i=0;i<h;i++)
{
in=(Byte *)img->Picture->Bitmap->ScanLine;
for(j=0;j<w;j++)
{
out=(Byte *)bmp->ScanLine[j];
out[h-1-i]=in[j];
}
}
img->Picture->Bitmap->Assign(bmp);
delete bmp;
}