Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
I have a form with a picture and a button. I want to each time click on button, picture will rotate 30 degree.I found in internet but there is not.Usually they use 2 picture but I only use 1 picture.
 
If you know, please help me.
 
thanks for advance
Posted 21-Mar-11 0:17am
ngthtra1.4K
Edited 21-Mar-11 1:05am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Did you already have a look at this excellent article: Image Transition in VB.NET Windows Forms[^]
  Permalink  
Comments
santosh dhanawade at 21-Mar-11 5:31am
   
5+
For link of such a excellent application.
SAKryukov at 21-Mar-11 5:39am
   
I don't think you voted.
--SA
Mika Wendelius at 21-Mar-11 5:51am
   
Funny that I received an email since you replied to santosh's post. Do you know if this is the expected behaviour (all replies on ones solutions are sent to the person who originally posted the solution)?
SAKryukov at 21-Mar-11 5:53am
   
As far as I can understand, yes (and this is reasonable). Not sure about other cases.
--SA
Mika Wendelius at 21-Mar-11 5:55am
   
I agree, it makes sense. I was just little surprised since the behaviour differs from the forums, but then again that makes sense also :)
Mika Wendelius at 21-Mar-11 5:47am
   
Agree, the article was magnificent. Had to leave a vote while skimming through it :)
SAKryukov at 21-Mar-11 5:38am
   
Agree. My 5.
--SA
Mika Wendelius at 21-Mar-11 6:04am
   
Thanks :)
ngthtra at 21-Mar-11 6:23am
   
link is very good but it did not resolve my problem. please give another way.
Mika Wendelius at 21-Mar-11 6:44am
   
Without knowing why it didn't solve the problem it's kinda hard to give alternatives. But did you have a look at the links Abhinav posted. There are some really good and simple examples.
Dalek Dave at 22-Mar-11 10:03am
   
Good call.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Comments
SAKryukov at 21-Mar-11 5:54am
   
*Much* more than enough, my 5.
--SA
Abhinav S at 21-Mar-11 5:57am
   
Thank you.
Mika Wendelius at 21-Mar-11 6:03am
   
Extensive collection +5.
Abhinav S at 21-Mar-11 6:03am
   
Thanks.
Dalek Dave at 22-Mar-11 10:04am
   
Good links, 5.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

you can use matrices wich found in :
Drawing2D.Matrix
I wrote this example for you it can help:
create new form and add a button named as button1 then write the folowing
Public Class Form1
    Dim gr As Graphics
    Dim mat As New Drawing2D.Matrix
    Dim im As Image
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As  _
System.EventArgs) Handles Me.Load
        ' create your graphics object using this method
        gr = Me.CreateGraphics
        im = Image.FromFile("Write your Image directory here")
    End Sub
 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As  _
System.EventArgs) Handles Button1.Click
        'rotate matrix around specific point
        mat.RotateAt(30, New Point(100, 200))
        gr.Transform = mat
    End Sub
 
    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As  _
 System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        'very important to clear your device before drawing, choose any color to clear it
        gr.Clear(Color.Wheat)
        'image center match the rotation center
        gr.DrawImage(im, 75, 175, 50, 50)
    End Sub
End Class
 
you can have a look in my tutorial in directX transformation , i know it s different but you can get some usefull ideas Basic Directx Transformation with VB.NET
  Permalink  
v3
Comments
Dalek Dave at 22-Mar-11 10:04am
   
Good Answer
Abudreas at 22-Mar-11 10:10am
   
Thanks
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

thanks anybody. I found the best way to resolve my problem and I think it is good.
 
Public Function RotateImg(ByVal bmpimage As Bitmap, ByVal angle As Single) As Bitmap
        Dim w As Integer = bmpimage.Width
        Dim h As Integer = bmpimage.Height
        Dim pf As PixelFormat = Nothing
        pf = bmpimage.PixelFormat
        Dim tempImg As New Bitmap(w, h, pf)
        Dim g As Graphics = Graphics.FromImage(tempImg)
        g.DrawImageUnscaled(bmpimage, 1, 1)
        g.Dispose()
        Dim path As New GraphicsPath()
        path.AddRectangle(New RectangleF(0.0F, 0.0F, w, h))
        Dim mtrx As New Matrix()
        'Using System.Drawing.Drawing2D.Matrix class
        
        mtrx.Rotate(angle)
        Dim rct As RectangleF = path.GetBounds(mtrx)
        Dim newImg As New Bitmap(Convert.ToInt32(rct.Width), Convert.ToInt32(rct.Height), pf)
        g = Graphics.FromImage(newImg)
        g.TranslateTransform(-rct.X, -rct.Y)
        g.RotateTransform(angle)
        g.InterpolationMode = InterpolationMode.HighQualityBilinear
        g.DrawImageUnscaled(tempImg, 0, 0)
        g.Dispose()
        tempImg.Dispose()
        Return newImg
    End Function
 
call this function:
 
Dim img As Bitmap
img = New Bitmap(My.Resources.bg4)
PictureBox1.Image = RotateImg(img, Convert.ToSingle(iAngel))
  Permalink  
Comments
Member 9336323 at 25-Oct-12 2:15am
   
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 120
4 DamithSL 95
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 15 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100