Rotate a bitmap 90 degrees

Source: Internet
Author: User

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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.