gpt4 book ai didi

java - 如何在不压缩的情况下在Android中保存图像?

转载 作者:搜寻专家 更新时间:2023-11-01 09:42:09 25 4
gpt4 key购买 nike

我正在制作一个 Android 应用程序,用于捕获图像并将它们存储在内部存储器中,但为了保存图像,我希望将其压缩为原始大小,而不进行任何压缩。

这是我用来存储图像的代码,因为我这样做不是压缩 ??

ContextWrapper cw = new ContextWrapper(context);

File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);

File mypath = new File(directory, "TheChat" + (System.currentTimeMillis()/1000) + "Avatar.jpg");

FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream(mypath);
bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {
if (fileOutputStream != null) {
fileOutputStream.flush();
fileOutputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}

最佳答案

将其保存为 BLOB(字节数组),然后在加载时将其重新转换为位图。如果它仅供内部使用,它应该可以正常工作。如果您根本不压缩它,您不妨将其保存为直接格式。

关于java - 如何在不压缩的情况下在Android中保存图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39439485/

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