This article describes how to rotate a bitmap 90 degrees. Add a Timage control to the project named Image1.
It works by creating a bitmap buffer to store the median, converting pixels from each row of the in-place diagram to each column and then storing it in the bitmap buffer we created. Finally, the rotated bitmap is saved back to the in-place diagram from the buffer.
//define buffered bitmap and cut the graphics area
Graphics::tbitmap *bufferbitmap=new graphics::tbitmap ();
bufferbitmap->width=image1- >Height;
bufferbitmap->height=image1->width;
Static Trect sourcepix,destpix,fullbufferimage,fulldestimage;
Fullbufferimage. left= 0;
Fullbufferimage. top= bufferbitmap->height;
Fullbufferimage. right= bufferbitmap->width;
Fullbufferimage. bottom= 0;
//rotate and copy in-situ to buffer bitmap
for (int y=0; y<image1->height; y++)
{
for (int x=0; x<image1->width; x + +)
{
Sourcepix. Left= x;
Sourcepix. Top= y+1;
Sourcepix. Right= x+1;
Sourcepix. Bottom= y;
Destpix. Left=y;
Destpix. top=bufferbitmap->height-x;
Destpix. right=y+1;
Destpix. bottom=bufferbitmap->height-x-1;
Bufferbitmap->canvas->copyrect (Destpix,image1->canvas,sourcepix);
}
}
//Adjust the size of the in-place diagram and copy the rotated buffered bitmap to the in-place diagram
Image1->width=bufferbitmap->width
Image1->height=bufferbitmap->height;
image1->picture->bitmap->width=bufferbitmap->width;
image1->picture->bitmap->height=bufferbitmap->height;
Image1->canvas->copyrect (fullbufferimage,bufferbitmap->canvas,fullbufferimage);