vb.net 以 15 度为增量旋转图像?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13773717/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 11:29:34  来源:igfitidea点击:

Rotate an image by 15 degrees increments?

.netvb.netimageimage-rotation

提问by Lethal Left Eye

I'm faced with what seems to be a very daunting task. I need to rotate an image, within a PictureBox, in increments of 15 degrees. After quite some time spent searching the depths of the internet, I've not found anything to achieve this task. The closest thing I could come up with was a 90 degree flip using:

我面临着一项似乎非常艰巨的任务。我需要在 PictureBox 中以 15 度为增量旋转图像。经过相当长的时间搜索互联网的深处,我没有找到任何东西来完成这项任务。我能想到的最接近的事情是使用以下方法进行 90 度翻转:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    InitializeBitmap()
End Sub

Dim bitmap1 As Bitmap

Private Sub InitializeBitmap()
    Try
        bitmap1 = CType(Bitmap.FromFile("G:\Documents\Dawson\Semster 3\Visual Basic I\Test\subs\subs\Wheel.bmp"), Bitmap)
        PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
        PictureBox1.Image = bitmap1
    Catch ex As System.IO.FileNotFoundException
        MessageBox.Show("There was an error. Check the path to the bitmap.")
    End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

    If bitmap1 IsNot Nothing Then
        bitmap1.RotateFlip(RotateFlipType.Rotate90FlipXY)
        PictureBox1.Image = bitmap1
    End If
End Sub

I'm in need of code that will flip my image by 15 degree increments; nothing more, and nothing less.

我需要将我的图像以 15 度为增量翻转的代码;仅此而已,也仅此而已。

Anyone willing to provide this code to me would be greatly appreciated. Thanks for your time.

任何愿意向我提供此代码的人将不胜感激。谢谢你的时间。

回答by Reed Copsey

Here is a CodeProject article showing how to rotate an image in a PictureBox.

这是一篇CodeProject 文章,展示了如何在 PictureBox 中旋转图像

The basic approach requires using GDI and the Graphics classto get the image, perform the rotation (via methods like Graphics.RotateTransform), then save the results as an image, and assign it to your PictureBoxcontrol.

基本的方法要求使用GDI和Graphics类以获取图像,进行旋转(通过类似方法Graphics.RotateTransform),然后将结果保存为图像,并将其分配给你的PictureBox控制。