Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rotate 8 bit bitmap?

Status
Not open for further replies.

inetd

Technical User
Jan 23, 2002
115
HK
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;
}

 
The only thing I can see is that you didn't re-assign the size of the picture on screen...I mean you didn't reset the width and height to be that of the rotated image. Perhaps this is inherently getting you later on.

Chris
 
If you assign an image to another image, it will convert the source image to the same pixel format as the destination so that the copying can begin. I'm guessing your screen isn't 256 colors. If it's 16 or 32bit, then what you're experiencing is normal because at some point your image will need to be (and is) converted to your screen's pixel format.

Try explicitely assigning the pixel format to pf8bit on both images before doing any pixel operations. At least check what the pixel format is each time to make sure my theory is correct.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top