首页 > 解决方案 > 在 vb.net 中裁剪图像

问题描述

我正在尝试裁剪图像并将裁剪的部分保存为单独的图像,但由于裁剪的图像显示空白屏幕,我没有这样做。

PFA 文件。

原始图像裁剪图像

下面是我的代码片段:

Dim bmp As Image = pdf.SaveAsImage(pageIndex)
Dim Bmp1 As Bitmap = New Bitmap(bmp)
zoneLeft = Convert.ToInt32((ZonesItems.Item(ClickedZoneCount - 1).ZoneArea.Left * 100) / ZoomPercent)
            zoneWidth = Convert.ToInt32((ZonesItems.Item(ClickedZoneCount - 1).ZoneArea.Width * 100) / ZoomPercent)
            zoneTop = Convert.ToInt32((ZonesItems.Item(ClickedZoneCount - 1).ZoneArea.Top * 100) / ZoomPercent)
            zoneHeight = Convert.ToInt32((ZonesItems.Item(ClickedZoneCount - 1).ZoneArea.Height * 100) / ZoomPercent)


Bmp1.Save("./Bmp1.tiff", Imaging.ImageFormat.Tiff)

bmp.Dispose()
bmp = Nothing

'X= 388, Y= 81, Width = 144, Height = 22. Dim rect As New RectangleF(X, Y, Width, Height) Dim Cropped As Bitmap = Bmp1.Clone(rect, Bmp1.PixelFormat)

Cropped.Save("./cropped.tiff", Imaging.ImageFormat.Tiff)

这就是我们计算 RECT 值的方式:

上面提到的值是在矩形函数中传递的。

任何人都可以让我知道我的代码中有什么问题吗?

标签: vb.netimage

解决方案


推荐阅读