为什么我的代码在VB 2008 GDI +中旋转单个图像不起作用? [英] Why is my code to rotate individual images in VB 2008 GDI+ not working?

查看:78
本文介绍了为什么我的代码在VB 2008 GDI +中旋转单个图像不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个流星列表,我需要根据旋转速度单独旋转。

尽管我尝试了一切,它根本不会旋转。

注意:图像按比例放大2.



I have a list of meteors that I need to rotate individually depending on the rotation speed.
Despite everything I have tried, it doesn't rotate at all.
Note: The image is scaled up by 2.

Private Sub Form1_Paint5(ByVal sender As Object, ByVal e As  _
    System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

    For Each I As Meteor In Meteors ' Rotate Meteors and draw meteors
        e.Graphics.Transform.RotateAt(5, New Point(I.Pos.X + I.Type.Width, I.Pos.Y + I.Type.Height))
        e.Graphics.DrawImage(I.Type, I.Pos.X, I.Pos.Y, I.Type.Width * 2, I.Type.Height * 2)
    Next
End Sub

推荐答案

因为Graphics.Transform返回转换矩阵的副本,而不是正在使用的矩阵。为了做你想做的事,你需要做这样的事情:



Because Graphics.Transform returns a copy of the transformation matrix, not the matrix being used. In order to do what you want, you would need to do something like this:

'Inside your loop
e.Graphics.Transform = e.Graphics.Transform.RotateAt(5 ...)





但你想在旋转之间保存你的图形状态,所以之前的旋转没有影响下一个,你可以通过保存GraphicsState并恢复它来实现。





But you would want to save your graphics state between rotations so the previous rotation does not affect the next one, you do this by saving the GraphicsState and restoring it.

Dim graphicsState as GraphicsState = e.Graphics.Save()
'do your transformation here, then draw your image
e.Graphics.Restore(graphicState)


这篇关于为什么我的代码在VB 2008 GDI +中旋转单个图像不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆