Android - 保存的图像中存在噪点
我的 Android 应用程序加载图像,进行一些处理并将处理后的图像保存在 SD 卡上。我将临时文件保存到 SD 卡而不是使用缓冲区。例如,读取背景、滚动图像、绘制注释、将背景和注释合并到已保存的临时文件中以用作下一个背景,等等。典型片段:
bitmap = Bitmap.createBitmap(imageSizeX, imageSizeY, Bitmap.Config.ARGB_8888);
位图 = BitmapFactory.decodeFile(路径, 选项);
bitmap.compress(Bitmap.compressFormat.JPEG, 100, 输出);
一切正常,但在某些情况下,保存的图像会添加类似于本文中描述的噪声: 位图调整大小和旋转:线性噪声
引用帖子的作者已解决通过二次采样来解决问题,但我不想这样做。
我已经尝试过这里建议的解决方案: http://www .curious-creature.org/2010/12/08/bitmap-quality-banding-and-dithering/#more-1218 如果我理解正确的话应该通过设置来实现: getWindow().setFormat(PixelFormat.TRANSLUCENT); 强制32位。
这并没有太大变化。设置或不设置抖动标志似乎也没有太大变化。还有其他想法吗?
My Android application loads images, does some processing and saves the processed images on the SD card. I save temporary files to the SD card instead of using buffers. For example, reading a background, scrolling the image, drawing an annotation, merging background and annotation in a saved temp file to use as next background, and so forth. Typical snippets:
bitmap = Bitmap.createBitmap(imageSizeX, imageSizeY, Bitmap.Config.ARGB_8888);
bitmap = BitmapFactory.decodeFile(path, options);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, output);
Everything works fine but in some cases the saved images have added noise similar to that described in this post:
Bitmap resizing and rotating: linear noise
The author of the post cited solved the problem by subsampling, but I don't wish to do that.
I have tried the solutions suggested here:
http://www.curious-creature.org/2010/12/08/bitmap-quality-banding-and-dithering/#more-1218
which if I understand correctly should be achieved by setting:
getWindow().setFormat(PixelFormat.TRANSLUCENT);
to force 32 bit.
which does not change much. Setting or not setting the dither flag does not seem to change much either. Any other ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回答我自己的问题:
通过压缩为 .png 而不是 .jpg,噪音消失了,或者至少结果更好了。
在 .jpg 中看起来像地毯纹理的天空在 .png 中看起来光滑干净。由于差异比压缩为 .png 和 .jpg 的同一图像之间的通常差异要明显得多,我想这取决于 Android 的实现。显式设置 TRANSLUCENT 和 DITHER 并不会以某种方式产生太大差异。
In answer to my own question:
The noise disappears, or at least the result is way better, by compressing to .png instead of .jpg
The same sky which looks like a carpet texture in .jpg looks smooth and clean in .png. Since the difference is much more evident than the usual difference between the same image compressed to .png and .jpg, I guess it depends on the Android implementation. Setting explicitly TRANSLUCENT and DITHER does not make much difference one way or another.