猿问

图像未以原始分辨率保存

这是以非常低的分辨率保存图像的代码。来自 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();

 }


FFIVE
浏览 197回答 1
1回答

ibeautiful

尝试如下: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();    }}
随时随地看视频慕课网APP

相关分类

Java
我要回答