如何将PictureBox内的图像旋转20度VB 2015?

时间:2016-10-23 08:22:08

标签: vb.net rotation image-rotation

说,我的表格中有一个PictureBox1。 PictureBox中有一个Image,我想旋转它。实际上,我已经学会了如何将图像旋转90,180,270度。但是我怎样才能将它旋转20度或45度?

这是我所学的

 PictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)

1 个答案:

答案 0 :(得分:-1)

我的解决方案:

Public Function RotateImage(ByRef image As Image, ByVal offset As PointF, ByVal angle As Decimal) As Bitmap
    If image Is Nothing Then
        Throw New ArgumentNullException("image")
    End If
    ''create a new empty bitmap to hold rotated image
    Dim rotatedBmp As Bitmap = New Bitmap(image.Width, image.Height)
    'Dim rotatedBmp As Bitmap = New Bitmap(image)
    rotatedBmp.SetResolution(image.HorizontalResolution, image.VerticalResolution)
    ''make a graphics object from the empty bitmap
    Dim g As Graphics = Graphics.FromImage(rotatedBmp)
    ''Put the rotation point in the center of the image
    g.TranslateTransform(offset.X, offset.Y)
    ''rotate the image
    g.RotateTransform(angle)
    ''move the image back
    g.TranslateTransform(-offset.X, -offset.Y)
    ''draw passed in image onto graphics object
    'g.DrawImage(image, New PointF(0, 0))
    g.DrawImage(image, offset)
    Return rotatedBmp
End Function