C # Image Processing: rotating an image from any angle

Source: Internet
Author: User

The above articles on C # digital image processing are all transferred from the column k1381.

Http://blog.csdn.net/ki1381/category/240835.aspx? Pagenumber = 1

Thank you !!

 

 

Occasionally, digital photos are being taken. It doesn't matter. We can still use C # To process images.

/// <Summary>
/// Rotate at any angle
/// </Summary>
/// <Param name = "BMP"> original map bitmap </param>
/// <Param name = "angle"> Rotation Angle </param>
/// <Param name = "bkcolor"> background color </param>
/// <Returns> output bitmap </returns>
Public static bitmap kirotate (bitmap BMP, float angle, color bkcolor)
...{
Int W = BMP. Width + 2;
Int H = BMP. height + 2;

Pixelformat PF;

If (bkcolor = color. Transparent)
...{
PF = pixelformat. format32bppargb;
}
Else
...{
PF = BMP. pixelformat;
}

Bitmap TMP = new Bitmap (W, H, Pf );
Graphics G = graphics. fromimage (TMP );
G. Clear (bkcolor );
G. drawimageunscaled (BMP, 1, 1 );
G. Dispose ();

Graphicspath Path = new graphicspath ();
Path. addrectangle (New rectanglef (0f, 0f, W, h ));
Matrix mtrx = new matrix ();
Mtrx. Rotate (angle );
Rectanglef RDBMS = path. getbounds (mtrx );

Bitmap DST = new Bitmap (INT) RDBMS. Width, (INT) RDBMS. Height, Pf );
G = graphics. fromimage (DST );
G. Clear (bkcolor );
G. translatetransform (-RDBMS. X,-RDBMS. y );
G. rotatetransform (angle );
G. interpolationmode = interpolationmode. highqualitybilinear;
G. drawimageunscaled (TMP, 0, 0 );
G. Dispose ();

TMP. Dispose ();

Return DST;
}

In the recent forum, it seems that C # is not suitable for image processing. My point is: if it is not highly real-time, otherwise C # is competent.

I made a C # personal digital photo processing tool with satisfactory processing speed. Except that Gaussian Blur is a little slow, everything else is very fast.

Of course, the premise is either bitmapdata or GDI +. In short, getpixel/setpixel cannot be used.

Related Article

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.