调整大小时图像模糊

时间:2014-05-22 00:48:50

标签: vb.net bitmap resize

我试图调整图像大小并将其显示在图片框中(64x64像素)。原始图像为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

1 个答案:

答案 0 :(得分:0)

尝试设置(对于像素放大):

e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
e.Graphics.PixelOffsetMode = Drawing2D.PixelOffsetMode.Half

其他绘图模式:

e.Graphics.CompositingQuality
e.Graphics.CompositingMode
e.Graphics.SmoothingMode

另外,可能需要GraphicsUnit.Pixel作为srcUnit param。