C # picturebox 360 degree rotation

Source: Internet
Author: User

Public static bitmap rotateimage (image, float angle)
{
If (image = NULL)
Throw new argumentnullexception ("image ");
Float dx = image. width/2.0f;
Float DY = image. Height/2.0f;

Bitmap rotatedbmp = new Bitmap (image. Width, image. Height );
Rotatedbmp. setresolution (image. horizontalresolution, image. verticalresolution );
Graphics G = graphics. fromimage (rotatedbmp );
G. translatetransform (dx, Dy );
G. rotatetransform (angle );
G. translatetransform (-dx,-dy );
G. drawimage (image, new pointf (0, 0 ));
Return rotatedbmp;
}

 

 

Void tm_elapsed (Object sender, eventargs E)
{
If (isstart)
{
Angle + = 5;
If (angle >=359) angle = 0;
Rotateimage (pic1, properties. Resources. _ 1, angle );
}
}

private void rotateimage (picturebox Pb, image IMG, float angle)
{< br> If (IMG = NULL | Pb. image = NULL)
return;
image oldimage = Pb. image;
Pb. image = utilities. rotateimage (IMG, angle);
If (oldimage! = NULL)
{< br> oldimage. Dispose ();
}< BR >}

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.