如何在 Android 中使用双三次插值在画布上绘制和缩放位图?
我想在画布上绘制比实际尺寸更大的位图。我可以使用 canvas.drawBitmap(bitmap, null, destRect, null);但这会导致质量很差,因为如果源图像比目标矩形小得多,结果就会像素化。
如何使用双线性或双三次重采样绘制位图?
任何帮助将不胜感激,谢谢。
I want to draw a bitmap on a canvas with bigger size than it is. I can use canvas.drawBitmap(bitmap, null, destRect, null); but that gives a poor quality, as the result is pixelated, if the source image is sightly smaller than the destination rectangle.
How can i draw my bitmap using bilinear or bicubic resampling?
Any help would be appreciated, thanx.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在绘画中设置 FILTER_BITMAP_FLAG 标志。
或者
这同样适用于
drawBitmap
方法的其他(语法糖)形式。大多数 Android 绘图选项都没有文档,也没有执行渲染的底层本机 Skia 库的文档。如果有的话我会更高兴。您可以在 Google 代码搜索上搜索 Skia 源代码。搜索 Skia 并挖掘原始来源;这是唯一的文档。
You need to set the FILTER_BITMAP_FLAG flag in your paint.
or
The same applies to other (syntactic sugar) forms of the
drawBitmap
method.There is no documentation anywhere for most of the Android drawing options and neither is there documentation for the underlying native Skia library that does the rendering. I'd be happier if there were. You can search the Skia source code on Google Code Search. Search for Skia and dig into the raw source; that's the only documentation.
在大多数情况下,FILTER_BITMAP_FLAG 不适用于缩小尺寸。
良好的缩小算法(不是像最近邻那样)仅包含 2 个步骤(加上输入/输出图像裁剪的精确矩形的计算):
以下是 SonyMobile 如何解决此任务的详细说明:https://web.archive.org/web/20140228024414/http://developer.sonymobile.com/2011/ 06/27/how-to-scale-images-for-your-android-application/
这是 SonyMobile 缩放工具的源代码:https://web.archive.org /web/20140227233706/http://developer.sonymobile.com/downloads/code-example-module/image-scaling-code-example-for-android/
FILTER_BITMAP_FLAG doesn't work for downscaling in most of the cases.
Good downscaling algorithm (not nearest neighbor like) consists of just 2 steps (plus calculation of the exact Rect for input/output images crop):
Here is detailed explanation how SonyMobile resolved this task: https://web.archive.org/web/20140228024414/http://developer.sonymobile.com/2011/06/27/how-to-scale-images-for-your-android-application/
Here is the source code of SonyMobile scale utils: https://web.archive.org/web/20140227233706/http://developer.sonymobile.com/downloads/code-example-module/image-scaling-code-example-for-android/