本文介绍了图像缩放与像素化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在轨道栏上使用此代码缩放图片框中的图片。
I am zooming image in picture box using this code on trackbar.
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为zoom。
actualSize是pbImage中图像的原始大小。
pbImage is a PictureBox control with sizemode as zoom.actualSize is original Size of Image in pbImage.
当我放大时,我得到没有像素化的图像。但是我想让它完全像素化并在缩放时显示MS Paint中显示的图像。任何帮助表示赞赏。欢迎使用VB.Net代码,C#代码或任何算法。
When I zoom in, I get image without pixelation. But I want it to get fully pixelated and show the image as shown in MS Paint on zooming. Any help is appreciated. VB.Net code, C# code or just any algorithm is welcomed.
推荐答案
在你的图片框中绘画:
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
pctBoxImage
是位图
将 800%缩放
或
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
是左上角位置的坐标位图。
valter
这篇关于图像缩放与像素化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!