Image Flipping and Rotating : Image « 2D Graphics « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Class Interface
3. Collections Data Structure
4. Components
5. Data Types
6. Database ADO.net
7. Design Patterns
8. Development Class
9. Event
10. File Stream
11. Generics
12. GUI Windows Form
13. Language Basics
14. LINQ
15. Network
16. Office
17. Reflection
18. Regular Expressions
19. Security
20. Services Event
21. Thread
22. Web Services
23. Windows
24. XML
25. XML LINQ
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C# / C Sharp » 2D Graphics » ImageScreenshots 
Image Flipping and Rotating
 
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

public class Form1 : System.Windows.Forms.Form {
    private System.Windows.Forms.GroupBox groupBox1;
    private System.Windows.Forms.CheckBox checkBox1;
    private System.Windows.Forms.RadioButton radioButton1;

    Image im = null;
    Image im2 = null;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.RadioButton radioButton2;
    private System.Windows.Forms.RadioButton radioButton3;

    public Form1() {
        this.groupBox1 = new System.Windows.Forms.GroupBox();
        this.radioButton1 = new System.Windows.Forms.RadioButton();
        this.checkBox1 = new System.Windows.Forms.CheckBox();
        this.label1 = new System.Windows.Forms.Label();
        this.radioButton2 = new System.Windows.Forms.RadioButton();
        this.radioButton3 = new System.Windows.Forms.RadioButton();
        this.groupBox1.SuspendLayout();
        this.SuspendLayout();

        this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
                                          this.radioButton3,
                                          this.radioButton2,
                                          this.radioButton1,
                                          this.checkBox1});
        this.groupBox1.Location = new System.Drawing.Point(31264);
        this.groupBox1.Size = new System.Drawing.Size(24880);

        this.radioButton1.Location = new System.Drawing.Point(12016);
        this.radioButton1.Size = new System.Drawing.Size(11224);

        this.checkBox1.Location = new System.Drawing.Point(1616);
        this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);

        this.label1.Location = new System.Drawing.Point(88);
        this.label1.Size = new System.Drawing.Size(304200);

        this.radioButton2.Location = new System.Drawing.Point(1648);
        this.radioButton3.Location = new System.Drawing.Point(12048);
        this.radioButton3.Size = new System.Drawing.Size(12024);

        this.AutoScaleBaseSize = new System.Drawing.Size(513);
        this.ClientSize = new System.Drawing.Size(560214);
        this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.label1,
                                      this.groupBox1});
        this.groupBox1.ResumeLayout(false);
        this.ResumeLayout(false);
        this.radioButton1.Checked = false;
        this.label1.Text = "";
        this.groupBox1.Text = "RotateFlipType";
        this.checkBox1.Text = "Paint";
        this.radioButton1.Text = "Rotate180FlipY";
        this.radioButton2.Text = "Rotate180FlipX";
        this.radioButton3.Text = "Rotate180FlipNone";

        this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButtons_CheckedChanged);
        this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButtons_CheckedChanged);
        this.radioButton3.CheckedChanged += new System.EventHandler(this.radioButtons_CheckedChanged);


    }
    [STAThread]
    static void Main() {
        Application.Run(new Form1());
    }
    protected override void OnPaint(PaintEventArgs e) { RotateFlip()}
    private void label1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { RotateFlip()}
    private void checkBox1_CheckedChanged(object sender, System.EventArgs e) { RotateFlip()}
    private void radioButtons_CheckedChanged(object sender, System.EventArgs e) { RotateFlip()}
    protected void RotateFlip() {
        Graphics g = Graphics.FromHwnd(this.label1.Handle);
        Brush b = new SolidBrush(this.label1.BackColor);

        if (this.checkBox1.Checked) {
            if (im == nullReadImage();
            Graphics g2 = Graphics.FromImage(im)
            FontFamily ff = new FontFamily("Times New Roman");
            Font f = new Font(ff, 25, FontStyle.Bold);
            g2.DrawString("HIMALAYA", f, new SolidBrush(Color.Yellow)170210);
            g2.Dispose();

            im2 = (Image)im.Clone();

            int w2 = label1.Width / 2, h2 = label1.Height / 2;
            g.DrawImage(im, 00, w2, h2);

            if (this.radioButton1.Checked){
                im2.RotateFlip(RotateFlipType.Rotate180FlipY);
                g.DrawImage(im2, w2, 0, w2, h2);
            else 
                g.FillRectangle(b, w2, 0, w2, h2);

            if (this.radioButton2.Checked) {
                im2.RotateFlip(RotateFlipType.Rotate180FlipX);
                g.DrawImage(im2, 0, h2, w2, h2);
            else 
                g.FillRectangle(b, 0, h2, w2, h2);

            if (this.radioButton3.Checked) {
                im2.RotateFlip(RotateFlipType.Rotate180FlipNone);
                g.DrawImage(im2, w2, h2, w2, h2);
            else 
                g.FillRectangle(b, w2, h2, w2, h2);
            im2.Dispose();
        else Clear(g);

        b.Dispose(); g.Dispose();
    }
    protected void ReadImage() {
        string path = "a.bmp";
        im = Image.FromFile(path);
        this.radioButton1.Enabled = true;
        this.radioButton2.Enabled = true;
        this.radioButton3.Enabled = true;
    }
    protected void Clear(Graphics g) {
        g.Clear(this.BackColor);
        g.Dispose();
        im = null;
        im2 = null;
        this.radioButton1.Checked = false;
        this.radioButton2.Checked = false;
        this.radioButton3.Checked = false;
        this.radioButton1.Enabled = false;
        this.radioButton2.Enabled = false;
        this.radioButton3.Enabled = false;
    }

}

 
Related examples in the same category
1. Load Image from an image file with Exception handler
2. Image.FromStream: load image from stream
3. Shrink ImageShrink Image
4. Shear ImageShear Image
5. Clone ImageClone Image
6. Get Image Resolution and Image size and Display sizeGet Image Resolution and Image size and Display size
7. Draw image based on its sizeDraw image based on its size
8. Set image resolution and paint itSet image resolution and paint it
9. Load image and displayLoad image and display
10. Fill Ellipse with image based Texture BrushFill Ellipse with image based Texture Brush
11. Image Save
12. Image Open
13. Thumbnail Image
14. Draw on Pixel-Size Image
15. Draw text on an Image
16. Partial Image Rotate
17. Partial Image Stretch
18. Draw Partial Image
19. Image At Points (Draw part of the image)
20. Image Reflection
21. Image Scale Isotropic
22. Image Scale To Rectangle
23. Center Pixel-Size Image by using Image.Width and Image.Height
24. Center an Image (VerticalResolution, HorizontalResolution)
25. Load image from a URL(Web) and draw it
26. Scribble with Bitmap
27. Image.GetThumbnailImage
28. Image Zoom
w___w___w_.___ja___v__a___2s_.__c_o__m | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.