【发布时间】:2017-07-14 00:28:18
【问题描述】:
我有一个 winforms 程序,它可以扫描文档并将其保存到文件中,然后它会打开另一个表单并将图像的裁剪部分加载到图片框中,但图像不会填满图片框。
执行此操作的代码如下:
Public Function Crop() As Image
' Function to rotate and crop the scanned image to speed up barcode reading
Dim Mystream As New FileStream(TempRoot & StrFileName & Exten, FileMode.Open)
Dim bitmap1 As New Bitmap(Mystream)
imageAttr1.SetGamma(2.2F)
' Rotates and crops the scanned document
Try
If bitmap1 IsNot Nothing Then
bitmap1.RotateFlip(RotateFlipType.Rotate270FlipNone)
End If
cropX = 1500
cropY = 200
cropWidth = 1100
cropHeight = 550
' Sets a rectangle to display the area of the source image
rect = New Rectangle(cropX, cropY, cropWidth, cropHeight)
' Create a new bitmap with the width and height values specified by cropWidth and cropHeight.
cropBitmap = New Bitmap(cropWidth, cropHeight)
' Creates a new Graphics object that will draw on the cropBitmap
g = Graphics.FromImage(cropBitmap)
' Draws the portion of the image that you supplied cropping values for.
g.DrawImage(bitmap1, 0, 0, rect, GraphicsUnit.Pixel)
g.DrawImage(cropBitmap, rect, 0, 0, OKTickets.ImgTicket.Width, OKTickets.ImgTicket.Height, GraphicsUnit.Pixel, imageAttr1)
Catch ex As System.IO.FileNotFoundException
MessageBox.Show("There was an error. Check the path to the bitmap.")
End Try
Mystream.Close()
Return cropBitmap
End Function
我在表单上有一个标签,显示图像的宽度和高度以及图片框的宽度和高度。
图片框的大小是宽度 = 1100 & 高度 = 550。
图像显示相同的大小,但仅填充图片框的左上角。
我已尝试将图片框大小模式设置为所有设置,但对图像完全没有影响。
谁能看出为什么它没有填满图片框?
【问题讨论】: