VB.NET只从图片中得到一个正方形

时间:2012-06-03 14:10:27

标签: vb.net pixel image

  

可能重复:
  VB.NET replace pixel color of picturebox image

我想从全图中提取正方形
全图:

full pic

我只想要这个:

expected

1 个答案:

答案 0 :(得分:3)

使用此功能应该起作用:

Public Function GetPicturePart(ByVal SourceImage As Image, ByVal Region As Rectangle) As Bitmap
    Dim ImagePart As Bitmap = New Bitmap(Region.Width, Region.Height)
    Using G As Graphics = Graphics.FromImage(ImagePart)
        Dim TargetRect As Rectangle = New Rectangle(0, 0, Region.Width, Region.Height)
        Dim SourceRect As Rectangle = Region
        G.DrawImage(SourceImage, TargetRect, SourceRect, GraphicsUnit.Pixel)
    End Using
    Return ImagePart
End Function

我认为这个功能是自我描述的。 ;)

来源:Get Picture Part