Android 不尊重颜色!
尝试调整存储在 SD 卡上的图像大小时,我注意到原始颜色发生了变化。看来 BitmapFactory.decodeFile 对此负责。下面是演示代码:
private void testImage() throws Exception{
BitmapFactory.Options o = new BitmapFactory.Options();
o.inDither = false;
o.inPreferredConfig = Bitmap.Config.ARGB_8888;
o.inScaled = false;
Bitmap b = BitmapFactory.decodeFile("/sdcard/test/original.jpg", o);
b.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream("/sdcard/test/result.jpg"));
b.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream("/sdcard/test/result.png"));
}
结果图像(original.jpg、result.jpg、result.png):
您可以看到,在两张生成的图像中,男孩的皮肤有点绿色。有什么技巧可以解决这个问题吗?
Trying to resize images stored on my sdcard, I noticed that original colors where altered. It seams that BitmapFactory.decodeFile is responsable for this. Here is a demonstration code:
private void testImage() throws Exception{
BitmapFactory.Options o = new BitmapFactory.Options();
o.inDither = false;
o.inPreferredConfig = Bitmap.Config.ARGB_8888;
o.inScaled = false;
Bitmap b = BitmapFactory.decodeFile("/sdcard/test/original.jpg", o);
b.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream("/sdcard/test/result.jpg"));
b.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream("/sdcard/test/result.png"));
}
Resulting images (original.jpg, result.jpg, result.png):
Has you can see, the skin of the boy is a bit green on the 2 resulting images. Any tips to solve this issue ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你怎么知道你原来的颜色不是绿色的?
您的相机/电脑可能已正确显示图片,因为它们正确应用了相机的颜色配置文件。你的代码显然没有。
问题可能在那里吗?尝试在相机/电脑以外的其他设备上查看图片。
How do you know your original colors weren't greenish?
Your camera/PC may have shown the picture correct because they applied the color profile of the camera correctly. Your code obviously didn't.
Could the problem be there? Try to check out the picture on some other device other than your camera/PC.