Your Ads Here

Friday 4 May 2012

Rotate Picture in PictureBox 90 degree using C#.NET


It shows to rotate image in picturebox to rotate 90 degree using C#.NET
Keywords: Rotation, rotate, 90, degree, .NET, image, CSharp.NET

For this add two controls
1)      PictureBox ( image must be added either through backgroundimage property or image property)
2)      Button

Here the full Code

 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace textcsharp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int width = 0;
            int height = 0;
            int X = 0;
            int Y = 0;

            // Make a Bitmap representing the input background Image
            Bitmap img_bitmap_In = new Bitmap(pictureBox1 .BackgroundImage);
            width = img_bitmap_In.Width;
            height = img_bitmap_In.Height;

            // Make the output bitmap.
            Bitmap img_bitmap_Out = new Bitmap(height, width);

            // Copy the pixel values.
            for (X = 0; X <= width - 1; X++)
            {
                for (Y = 0; Y <= height - 1; Y++)
                {
                    img_bitmap_Out.SetPixel(height - Y - 1, X, img_bitmap_In.GetPixel(X, Y));
                }
            }

            // Display the result.
            pictureBox1.BackgroundImage = img_bitmap_Out;

        }

     
    }
}




 Note: If you have any suggestion, please contact sivodayatech@dotnetdevelopertool.com

1 comment: