簡體   English   中英

圖像未保存為原始分辨率

[英]image not saving in original resolution

這是以非常低的分辨率保存圖像的代碼。來自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();
 }

嘗試如下:

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();
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM