0

裁剪(从图片中获取图像)所需的代码是什么?

4

1 回答 1

2

此代码通过从(矩形)输入图像中创建一个具有所需尺寸的较小矩形并将其加载到PictureBox( PictureBox1) 中来工作。这对于纸牌游戏软件很有用。

Private Function CropBitmap(ByRef bmp As Bitmap, ByVal cropX As Integer, ByVal cropY As Integer, ByVal cropWidth As Integer, ByVal cropHeight As Integer) As Bitmap 
    Dim rect As New Rectangle(cropX, cropY, cropWidth, cropHeight) 
    Dim cropped As Bitmap = bmp.Clone(rect, bmp.PixelFormat) 
    Return cropped 
End Function  
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
    Dim FN = "full path of the image file"
    Dim bmp As Bitmap bmp = Bitmap.FromFile(FN) 
    PictureBox1.Image = CropBitmap(bmp, 4, 4, 13, 16) 
End Sub
于 2013-08-20T02:06:23.133 回答