vb.net - 将缩放的像素化图像绘制到图片框
问题描述
我有一个 120x120 的 png 图像。我想取其中的一部分(10x10)并将其缩放 x32 倍并将其显示为picturebox
像素化的.
我做了什么:
bmp = New Bitmap(320, 320, PixelFormat.Format32bppArgb) 'create a bitmap x32
Dim g As Graphics = Graphics.FromImage(bmp)
'draw the part in that bitmap
g.DrawImage(My.Resources.MyImage, New Rectangle(0, 0, 320, 320), New Rectangle(50, 50, 10, 10), GraphicsUnit.Pixel)
PictureBox1.Image = bmp
g.Dispose()
图像没有像素化。我能做些什么来修复它?
解决方案
您必须在图形中指定:
g.InterpolationMode = InterpolationMode.NearestNeighbor
并将矩形更改为:
g.DrawImage(My.Resources.MyImage, New RectangleF(0, 0, 320, 320), New RectangleF(49.5, 49.5, 10, 10), GraphicsUnit.Pixel)
所以你不会损失半个像素。
推荐阅读
- javascript - 光滑的多个类相同的功能 - 寻找最佳解决方案
- javascript - 渲染threeJs渲染器列表的问题
- c# - 在 ASP.NET Core 中使用证书身份验证调用 WCF 服务,而不使用传输安全模式
- c++ - 图片上的文字
- json - 如何在 VSCode 设置中设置 Prettier 以按文件类型有条件地应用单引号?
- android - 无法在 Kotlin 中使用 Retrofit TypeAdapter 将 Gson Doubles 舍入为 Longs
- java - 是否可以在 Spring Boot 中停止打印 AmqpRejectAndDontRequeueException 堆栈跟踪日志?
- python - 将元组出现转换为数据框列中的字符串
- mysql - 无法连接本地数据库。Sequel Pro 遇到意外错误
- java - Hibernate-Search - 使用 lucene 查询解析器语法不区分大小写的通配符搜索(不使用 QueryBuilder!)