我正在尝试调整图像大小并将其显示在图片框中(64x64 px)。原始图像为8x8像素,但是当我将其尺寸调整为64x64像素时,图像会模糊。我不明白为什么,一切都保持比例。我使用颜料进行了测试,并且调整了图像的大小而没有模糊,所以我不明白为什么。这是代码。请注意,我首先需要从另一个图像获取图像。
Public Function GetPicturePart(ByVal SourceImage As Bitmap, 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
Private Function SizeImage(ByVal img As Bitmap, ByVal width As Integer, ByVal height As Integer) As Bitmap
Dim newBit As New Bitmap(width, height)
Dim g As Graphics = Graphics.FromImage(newBit)
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(img, 0, 0, width, height)
Return newBit
End Function
Private Sub AssembleSkin(ByVal Image As Image, ByVal Head As PictureBox, ByVal Body As PictureBox, ByVal LeftArm As PictureBox, ByVal RightArm As PictureBox, ByVal RightLeg As PictureBox, ByVal LeftLeg As PictureBox)
Head.Image = SizeImage(GetPicturePart(My.Resources.james222, New Rectangle(New Point(8, 8), New Size(8, 8))), 64, 64)
End Sub
尝试设置(用于像素放大):
e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
e.Graphics.PixelOffsetMode = Drawing2D.PixelOffsetMode.Half
其他绘图模式:
e.Graphics.CompositingQuality
e.Graphics.CompositingMode
e.Graphics.SmoothingMode
同样,可能需要GraphicsUnit.Pixel作为srcUnit参数。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句