createScaledBitmap 的过滤器参数有什么作用?
android.graphics.Bitmap.createScaledBitmap
的声明是
public static Bitmap createScaledBitmap
(Bitmap src, int dstWidth, int dstHeight, boolean filter)
但是,文档没有解释任何参数。除了布尔过滤器之外,所有这些都非常明显。有谁知道它有什么作用?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
扩展卡兰的答案:作为一般规则,如果您向下缩放图像,您不会看到任何差异,但如果您向上缩放图像,就会看到任何差异。
传递
filter = false
将产生块状、像素化的图像。传递
filter = true
将为您提供更平滑的边缘。然而,正如 EIYeante 在评论中指出的那样,您可能仍然会看到差异。 这是他们的示例图片。
To expand on Karan's answer: As a general rule you won't see any difference if you're scaling your image down, but you will if you're scaling it up.
Passing
filter = false
will result in a blocky, pixellated image.Passing
filter = true
will give you smoother edges.However, as EIYeante pointed out in the comments, you might still see a difference. This is their example image.
快速浏览 SKIA 源代码表明(至少在默认情况下)FILTER 标志使其执行简单的双线性插值。检查维基百科或您最喜欢的图形参考,看看预期的后果是什么。传统上,您希望在放大图像时进行双线性或双三次插值,在缩小图像时进行区域平均。我的印象是(尽管我很高兴得到纠正)Android/Skia 在缩小规模时会进行简单的子采样而不进行过滤,因此即使在缩小规模时,您也可能会通过过滤获得更好的结果。 (有一种通过插值获得高质量缩小规模的替代方法,涉及进行一系列 50% 的规模缩小。请参阅 http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html 了解详细信息。)
A quick dig through the SKIA source-code indicates that (at least by default) the FILTER flag causes it to do a straightforward bilinear interpolation. Check Wikipedia or your favorite graphics reference to see what the expected consequences are. Traditionally, you want to do bilinear or bicubic interpolation when upsizing images, and area averaging when downsizing images. I get the impression (though I'm glad to be corrected) that Android/Skia does simple subsampling when downsizing without filtering, so you are likely to get better results from filtering even when downsizing. (There's an alternate method for getting high quality downsizing with interpolation, involving doing a series of 50% scale reductions. See http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html for details.)
聚会有点晚了,但我认为一些示例图片可能会澄清这个问题。
有一个更普遍的问题是关于是否以及如何过滤超级用户。
杰夫·阿特伍德说:
Android 的 API 没有指定将应用哪种类型的过滤器,所以我想问题是:您是否希望像素保持原样(如您在 8 位艺术中所希望的那样),或者是否可以将转换应用于使图像更令人愉悦(就像您在照片中所希望的那样)。
A bit late to the party, but I thought some sample images might clarify the issue.
There is a more general question about whether and how to filter on superuser.
Says Jeff Atwood:
Android's API does not specify what kind of filter would be applied, so I guess the question is: do you want your pixels to remain as they are (as you would want in 8-bit art) or is it okay to apply a transformation to make the image more palatable (as you would want in photographs).
过滤器将设置 FILTER_BITMAP_FLAG 进行绘制当位图根据您提供的值进行转换时,会影响位图的采样。
Filter will set the FILTER_BITMAP_FLAG for painting which affects the sampling of bitmaps when they are transformed based on the value that you provide.
在我研究 filter=false 时使用的算法(我需要 100% 确定生成什么输出)时,因为我在 android 和 python 上使用相同的tensorflow lite模型,发现它使用 NEAREST (在 android 7.1 上测试)当 filter=false 时。我比较了使用 PIL resample=Image.NEARES 时 Android 和 Python 上相同的嵌入 T
During my research about used algorithm when filter=false (I needed to be 100% sure what output is produced) as I was using the same tensorflow lite model on android and python and found that it uses NEAREST (tested on android 7.1) when filter=false. I've compared embeddings which were identical on android and on python when used PIL resample=Image.NEAREST