【问题标题】:Image zoom WITH pixelation像素化图像缩放
【发布时间】:2014-02-18 23:52:56
【问题描述】:

我正在使用轨迹栏上的此代码放大图片框中的图像。

Private Sub tbrZoomLevel_Scroll(sender As System.Object, e As System.EventArgs) Handles tbrZoomLevel.Scroll
    With pbImage
        .SuspendLayout()
        .Width = actualSize.Width * tbrZoomLevel.Value
        .Height = actualSize.Height * tbrZoomLevel.Value
        .ResumeLayout()
    End With
End Sub

pbImage 是一个 PictureBox 控件,以 sizemode 作为缩放。 actualSize 是 pbImage 中图像的原始大小。

当我放大时,我得到的图像没有像素化。但我希望它完全像素化并显示图像,如 MS Paint on zooming 所示。任何帮助表示赞赏。欢迎使用 VB.Net 代码、C# 代码或任何算法。

【问题讨论】:

    标签: vb.net winforms image


    【解决方案1】:

    在您的图片框中绘画:

    Private Sub PictureBox1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
    
        e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
        'Draw the image
    End Sub
    

    编辑:试试这个

    Private Sub PictureBox1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
        Dim srcRect As RectangleF = New Rectangle(0, 0, PictureBox1.Width / 8, PictureBox1.Height / 8)
        Dim dstRect As RectangleF = New RectangleF(0, 0, PictureBox1.Width, PictureBox1.Height)
    
        e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
        e.Graphics.DrawImage(pctBoxImage, dstRect, srcRect, GraphicsUnit.Pixel)
    End Sub
    

    pctBoxImagebitmap,它将是 800% zoomed

    Private Sub PictureBox1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
        e.Graphics.ScaleTransform(8, 8)
        e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
        e.Graphics.DrawImage(pctBoxImage, 0, 0)
    End Sub
    

    0,0 是位图左上角位置的坐标。

    变态

    【讨论】:

    • 我希望图像在放大时正确显示其像素,就像在缩放时 MS 绘制一样。插值正好与此相反。在 MS Paint 中拍照,放大 uptu 600 或 800 %,你会看到像素变得越来越大。我想要同样的行为。
    • @Sarvesh 这正是您所需要的。你会看到像素。查看我的编辑
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-18
    • 2020-05-12
    • 1970-01-01
    • 2019-09-17
    • 2014-02-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多