下面的代码从某个位置获取图像 - 并使该图像压缩图像。 但是我需要将压缩图像作为文件...我该怎么做?
File compressFile = null;
File file = new File("MyFile");
OutputStream fOut = new FileOutputStream(file);
if(image.compress(Bitmap.CompressFormat.PNG, 100, fOut))
{
fOut.flush();
fOut.close();
compressFile = ??? // I need here to make the OutputStream to be back to file.
}
最佳答案
image.compress
已经将图像写入文件,假设您提供了正确的文件名。
所以像这样使用它:
File file = new File(Environment.getExternalStorageDirectory() + "/myimage.png");
FileOutputStream fOut = new FileOutputStream(file);
image.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.close();
https://stackoverflow.com/questions/8296248/