dotnet-Snippets.com
Snippets: 61 | Registered User: 61 | Visitors online: 8
Main Menu

Home
Random Snippet
FAQs
Contact Us
Imprint
RSS Feeds

Rss All languages
Rss C#
Rss VB.NET
Rss C++
Rss J#
Rss ASP.NET
Google Ads

Sri Lanka .NET 
                Forum Member
Image rotation by angle

Author: Jan Welker
Programming Language: C# Rating:
not yet rated

Views: 4738

Description:

Rotates the image by angle.



C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/// <summary>
/// Rotates the image by angle.
/// </summary>
/// <param name="oldBitmap">The old bitmap.</param>
/// <param name="angle">The angle.</param>
/// <returns></returns>
private static Bitmap RotateImageByAngle(System.Drawing.Image oldBitmap, float angle)
{
    var newBitmap = new Bitmap(oldBitmap.Width, oldBitmap.Height);
    var graphics = Graphics.FromImage(newBitmap);
    graphics.TranslateTransform((float)oldBitmap.Width / 2, (float)oldBitmap.Height / 2);
    graphics.RotateTransform(angle);
    graphics.TranslateTransform(-(float)oldBitmap.Width / 2, -(float)oldBitmap.Height / 2);
    graphics.DrawImage(oldBitmap, new Point(0, 0));
    return newBitmap;
}


This Snippets could be interesting for you:

Poor Excellent
1 2 3 4 5 6 7 8 9 10
Sign in to vote for this snippet.

Comments:
(Please log in to wrtite an comment.)