【问题标题】:Re-size a bitmap using "Nearest Neighbor" in .net使用 .net 中的“最近邻”调整位图大小
【发布时间】:2011-09-25 18:42:21
【问题描述】:

我有一些低细节的图像要渲染到屏幕上。我使用位图作为缓冲区。有没有办法在.net 中重新调整位图的大小(使用“最近邻”)?

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

【问题讨论】:

    标签: vb.net bitmap resize nearest-neighbor


    【解决方案1】:

    一个简单的 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
    

    【讨论】:

      猜你喜欢
      • 2014-11-15
      • 2017-02-01
      • 2018-12-04
      • 2023-03-17
      • 2020-05-20
      • 2021-12-12
      • 2022-10-13
      • 2017-06-11
      • 1970-01-01
      相关资源
      最近更新 更多