gpt4 book ai didi

java - android 更好地保存图像选项?

转载 作者:行者123 更新时间:2023-11-30 09:31:16 25 4
gpt4 key购买 nike

目前我正在使用压缩的方式将android手机上的相机硬件拍摄的图像保存到SD卡中。

try {
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 10;
Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0,
imageData.length,options);

fileOutputStream = new FileOutputStream(
sdImageMainDirectory.toString() +"/"+fileName+".png");

BufferedOutputStream bos = new BufferedOutputStream(
fileOutputStream);
myImage.compress(CompressFormat.PNG, 100, bos);
bos.flush();
bos.close();

现在这工作得很好,但是,它保存的图像质量很难让您一开始就值得拍照。我正在寻找以更高质量保存图片的更好方法。

最佳答案

options.inSampleSize = 10;

这是你的质量损失:这将在 heigthwidth

中创建 1/10 的图像

来自文档:

If set to a value > 1, requests the decoder to subsample the original image, returning a smaller image to save memory. The sample size is the number of pixels in either dimension that correspond to a single pixel in the decoded bitmap. For example, inSampleSize == 4 returns an image that is 1/4 the width/height of the original, and 1/16 the number of pixels. Any value <= 1 is treated the same as 1. Note: the decoder will try to fulfill this request, but the resulting bitmap may have different dimensions that precisely what has been requested. Also, powers of 2 are often faster/easier for the decoder to honor.

关于java - android 更好地保存图像选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12957793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com