图像像素格显示
本帖最后由 niceliu2011 于 2014-03-22 12:06:43 编辑
在图像显示编程中,放大图像后很模糊,而用系统画图工具放大同样倍率后可以显示出像素格,怎样才能实现这样的效果呢,请各位大侠指点,先谢过!!! 代码如下:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim img As Image = Image.FromFile("D:\8.tif")
Dim x As Graphics = Me.CreateGraphics
x.DrawImage(img, 20, 20, img.Width * 6, img.Height * 6)
End Sub
图像放大后对比如下:
放大后有像素格(想做成这样)
放大后没有像素格(目前状况)
------解决方案--------------------可以用InterpolationMode.NearestNeighbor
static Bitmap Mosaic(Bitmap original, int scale)
{
Bitmap result = new Bitmap(original.Width * scale, original.Height * scale);
using (Graphics g = Graphics.FromImage(result))
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; //<---
g.DrawImage(original, 0, 0, result.Width, result.Height);
}
return result;
}
引用自http://bbs.csdn.net/topics/350144818