这是以非常低的分辨率保存图像的代码。来自url的图像太大,但是当我通过此代码保存图像时,则会减小图像的大小和分辨率
private void saveImage(final String uri) throws IOException,
IllegalStateException {
URL url = new URL(uri);
InputStream input = url.openStream();
File storagePath = Environment.getExternalStorageDirectory();
OutputStream output = new FileOutputStream(storagePath + "/myImage.png");
try {
byte[] buffer = new byte[2048];
int bytesRead = 0;
while ((bytesRead = input.read(buffer, 0, buffer.length)) >= 0) {
output.write(buffer, 0, bytesRead);
}
} finally {
output.close();
}
答案 0 :(得分:0)
尝试如下:
Bitmap bitmapImage; //your input bitmap to save
File storagePath = Environment.getExternalStorageDirectory();
OutputStream output = new FileOutputStream(storagePath + "/myImage.png")
try {
// Use the compress method on the BitMap object to write image to the OutputStream
bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, output);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}