.net - .Net 中的图形错误图像插值

标签 .net vb.net image graphics drawing

我有一个简单的测试。当它解决时,我的问题也解决了。 当处理小图像时,图形插值的效果很差。

请检查您是否知道如何解决以下代码中的结果图像忽略要绘制的图像的后半部分的问题。 使用 JPG 中的 loadimage 或任何您想要的东西在图像上绘制一些内容。

    Dim GrayImage as system.drawing.Bitmap(640,480)    
    Dim bmTmp As New System.Drawing.Bitmap(GrayImage.Width, 1)
    Using gr As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(bmTmp)
         gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None
         gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear
         gr.DrawImage(GrayImage, New System.Drawing.Rectangle(0, 0, bmTmp.Width, bmTmp.Height), New System.Drawing.Rectangle(0, 0, GrayImage.Width - 0, GrayImage.Height - 0), System.Drawing.GraphicsUnit.Pixel)
     End Using

     GrayImage = New System.Drawing.Bitmap(GrayImage.Width, GrayImage.Height, GrayImage.PixelFormat)
     Using gr As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(GrayImage)
         gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None
         gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor
         gr.DrawImage(bmTmp, New System.Drawing.Rectangle(0, 0, GrayImage.Width, GrayImage.Height ), New System.Drawing.Rectangle(0, 0, bmTmp.Width - 0, bmTmp.Height - 0), System.Drawing.GraphicsUnit.Pixel)
     End Using

Source stretched to let you view it 在这里下载原始来源:http://www.goldengel.ch/temp/Source01%20one%20Pixel.jpg (一张像素高度图像)

Destination image without fully drawing in half 垂直的后半部分不是使用 DrawImage 方法绘制的。我希望得到如第一张图片所示的结果。拉伸(stretch)图像,整个内容带有源。

* 下载* 在此下载完整的 VS2010 VB.Net 演示项目:

VS2010 Scaling Project with description - Timo Böhme

最佳答案

请尝试添加:

gr.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality

到你的最后一个条款。我猜 GDI 魔法:)

希望这有帮助!

关于.net - .Net 中的图形错误图像插值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7649288/

相关文章:

c# - 获取字典中的最后一个元素?

c# - 更改 FileHelpers EOL 字符

c# - .NET 中基于屏幕键盘的组合框建议

python - 在Python中手动编写warpAffine代码

jQuery 动画不稳定

asp.net - web api TaskScheduler.UnobservedTaskException

.NET 6 Linux 多容器应用程序无法在 Azure 应用服务中建立容器内部通信

JavaScript、页面方法和 Gridview

regex - 删除 3 个特定字符,如果存在于字符串 VB.net 的开头

wpf - 如何在 WPF 中拉伸(stretch)位图而不平滑像素