CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2010
    Posts
    3

    [RESOLVED] c# rotate image

    hello
    the title says everything, i want to rotate an image but it dont rotate around his center it rotates in a circle around the form.

    Code:
    for(int i=0;i<500;i++)
    {
    Image m=Image.FromFile("C:/p1.png");
    using(Graphics g=this.CreateGraphics())
    {
    
    g.TranslateTransform(m.Width/2,m.Height/2);
    
    
    g.RotateTransform(i);
    g.TranslateTransform(-m.Width/2,-m.Height/2);
    g.DrawImage(m,new Point(100,100));
    
    
    }
    }
    if I put in DrawImage(m,0,0) i works great but i dont want to rotate the image in the corner.
    sorry for the english but I think you understud what I ask
    Last edited by HanneSThEGreaT; March 19th, 2010 at 02:56 AM.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: c# rotate image

    You don't need to Transform, you need to Rotate only
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: c# rotate image

    wert1234, please make use of &#091;CODE] tags when posting code

  4. #4
    Join Date
    Mar 2010
    Posts
    3

    Re: c# rotate image

    Quote Originally Posted by dglienna View Post
    You don't need to Transform, you need to Rotate only
    if I remove the Transform it work samo, the image rorates over the form


    Quote Originally Posted by HanneSThEGreaT View Post
    wert1234, please make use of [CODE] tags when posting code
    sorry for that
    Attached Images Attached Images  

  5. #5
    Join Date
    Mar 2010
    Posts
    3

    Re: c# rotate image

    problem solved

    Code:
    Image m = Image.FromFile(@"C:\p1.png");
              
    using (Graphics gfx = this.CreateGraphics())
    {
        for (int i = 0; i <= 360; i++)
        {       
            Bitmap b = new Bitmap(m.Width, m.Height);
    
            using (Graphics g = Graphics.FromImage(b))
            {
                g.TranslateTransform(m.Width / 2, m.Height / 2);
                g.RotateTransform(i);
                g.TranslateTransform(-m.Width / 2, -m.Height / 2);
                g.DrawImage(m, 0, 0);             
            }
            
           gfx.DrawImage(b, 100, 100);
           b.Dispose();
        }
    }
    the thread can be locked, deleted or what you want

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: c# rotate image

    You should mark it resolved. Follow these steps :

    http://www.codeguru.com/forum/showthread.php?t=403073

  7. #7
    Join Date
    Apr 2013
    Posts
    2

    Re: [RESOLVED] c# rotate image

    this is a method i found on the internet, you can give a try. a way of rotating an image

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured