createScaledBitmap 的过滤器参数有什么作用?

发布于 2024-09-03 01:43:56 字数 247 浏览 5 评论 0 原文

android.graphics.Bitmap.createScaledBitmap 的声明是

public static Bitmap createScaledBitmap
  (Bitmap src, int dstWidth, int dstHeight, boolean filter)

但是,文档没有解释任何参数。除了布尔过滤器之外,所有这些都非常明显。有谁知道它有什么作用?

The declaration of android.graphics.Bitmap.createScaledBitmap is

public static Bitmap createScaledBitmap
  (Bitmap src, int dstWidth, int dstHeight, boolean filter)

However, the documentation doesn't explain any of the parameters. All of them are pretty obvious except for boolean filter. Does anyone know what it does?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

长安忆 2024-09-10 01:43:56

扩展卡兰的答案:作为一般规则,如果您向下缩放图像,您不会看到任何差异,但如果您向上缩放图像,就会看到任何差异。

传递 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.

小嗷兮 2024-09-10 01:43:56

快速浏览 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.)

云之铃。 2024-09-10 01:43:56

聚会有点晚了,但我认为一些示例图片可能会澄清这个问题。

图像过滤器比较

有一个更普遍的问题是关于是否以及如何过滤超级用户

杰夫·阿特伍德说:

一般来说,当将较大的图像变成较小的图像时,您需要轻微的锐化效果,而当将较小的图像变成较大的图像时,您需要轻微的模糊效果。

Android 的 API 没有指定将应用哪种类型的过滤器,所以我想问题是:您是否希望像素保持原样(如您在 8 位艺术中所希望的那样),或者是否可以将转换应用于使图像更令人愉悦(就像您在照片中所希望的那样)。

A bit late to the party, but I thought some sample images might clarify the issue.

image filters compared

There is a more general question about whether and how to filter on superuser.

Says Jeff Atwood:

In general you want a mild sharpening effect when making a larger image into a smaller one, and a mild blurring effect when making a smaller image into a larger one.

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).

奢望 2024-09-10 01:43:56

过滤器将设置 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.

随心而道 2024-09-10 01:43:56

在我研究 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文