使用.net中的“最近邻居”重新调整位图大小

时间:2011-09-25 18:42:22

标签: vb.net bitmap resize nearest-neighbor

我有一些低细节图像,我正在渲染到屏幕上。我正在使用位图作为缓冲区。有没有办法在.net?

中重新调整位图的大小(使用“最近邻居”)

我正在使用VB.net,所以所有.net解决方案都可以接受。

1 个答案:

答案 0 :(得分:5)

一个简单的Winforms示例,它绘制了一个已添加为资源的缩放图像,其名称为“SmallImage”,带有最近邻插值:

Public Class Form1
    Public Sub New()
        InitializeComponent()
        Me.SetStyle(ControlStyles.ResizeRedraw, True)
        Me.DoubleBuffered = True
        Me.bmp = My.Resources.SmallImage
    End Sub

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
        e.Graphics.PixelOffsetMode = Drawing2D.PixelOffsetMode.Half
        Dim h = Me.ClientSize.Width * bmp.Height / bmp.Width
        e.Graphics.DrawImage(bmp, New Rectangle(0, 0, Me.ClientSize.Width, h))
    End Sub

    Private bmp As Bitmap

End Class