I just copied and pasted this code from bytamin-c.com. It will rotate a bitmap 90 degrees.
The code works this way; it creates a buffer image to store the proceedings, then takes each line of the image and changes it as a column on the buffer image. Finally, it transfers the result back to the original image.
//definitions of a buffer bitmap and the clipping rectangles
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 the original image, pixel by pixel, to the buffer image (look at the changes in the //coordinates of sourcepix and destinationpix).
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 original image to the new dimensions and
//copy the buffered rotated image to the original image
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);
Cyprus