我正在使用 Visual Studio Express 2012。我有一个主背景图像,我想倾斜图像并将其添加到主背景中。
到目前为止,我有这个:
'Create a new bitmap image of the transparent image
Dim overlay As New Bitmap("C:\TestFolder\rectangle.png")
'Create a new bitmap image of the image to you want the transparent image drawn onto
Dim pic As New Bitmap("C:\TestFolder\MyImage.png")
'Create a graphics object from the image to be drawn onto
Dim grx As Graphics = Graphics.FromImage(pic)
'Draw the transparent image into the picture
grx.DrawImage(overlay, 100, 100)
'Dispose the graphics object
grx.Dispose()
'Save the new image that you just put the transparent image on
pic.Save("C:\TestFolder\NewImage.jpg", Imaging.ImageFormat.Jpeg)
'Dispose both new bitmap images because they are not needed anymore
overlay.Dispose()
pic.Dispose()
我设法将图像绘制在另一个图像之上,但我无法将其倾斜并使用像素位置放置在正确的位置。
编辑 我还添加了这段代码:
Dim destinationPoints As Point() = { _
New Point(518, 0), _
New Point(743, 0), _
New Point(518, 288), _
New Point(743, 377)}
Dim image As New Bitmap("C:\TestFolder\this.png")
' Draw the image unaltered with its upper-left corner at (0, 0)
e.Graphics.DrawImage(image, 518, 0)
' Draw the image mapped to the parallelogram
e.Graphics.DrawImage(image, destinationPoints)
但是每次我运行它,我都会收到这个错误:
WindowsApplication4.exe 中发生了“System.InvalidCastException”类型的未处理异常
附加信息:无法将“System.Windows.Forms.MouseEventArgs”类型的对象转换为“System.Windows.Forms.PaintEventArgs”类型。