日期:2014-05-17  浏览次数:20710 次

使用GDI+绘图时候发生的文图,图像只画了一部份,请教一下大家
本帖最后由 wangwei244157887 于 2013-01-19 22:12:47 编辑

如上图所示,当我用GDI+使图片旋转的时候,发现图片只显示了一部分,这是哪里出错了,想不出哪里出问题了,郁闷,下面是代码,请大家指教一下


   Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Dim ag As Graphics
        ag = Me.CreateGraphics
        Dim pbleft, pbtop As Single
        pbleft = 312 + 60
        pbtop = 169 + 60
        Dim rotatePoint As New PointF(pbleft, pbtop)
        Dim mymatrix As New Matrix
        mymatrix.RotateAt(-10, rotatePoint, MatrixOrder.Append)
        ag.Transform = mymatrix
        Dim newImage As Image = Image.FromFile("D:\66.png")
        Dim ulCorner As New PointF(312.0F, 169.0F)
        ag.DrawImage(newImage, ulCorner)
        ag.Dispose()

    End Sub



图片大小是120×120

------解决方案--------------------
1.首先设置Graphics旋转中心为图形中心
2.旋转指定角度,单位(度)
3.绘图
4.回复Graphics旋转中心

                Graphics g = e.Graphics;
                g.TranslateTransform(pictureBox1.Width / 2, pictureBox1.Height / 2);
                g.RotateTransform(angle);
                g.DrawImage(boximg, -pictureBox1.Width / 2, -pictureBox1.Height / 2, pictureBox1.Width, pictureBox1.Height);
                g.RotateTransform(-angle);
                g.ResetTransform();