2011-09-07 131 views

回答

-2

您從相機獲得的圖像已經以jpeg格式壓縮。你永遠不會從相機獲得原始圖像。

0

您可以使用下面的代碼重新調整圖像大小。

Bitmap yourBitmap; 
Bitmap resized = Bitmap.createScaledBitmap(yourBitmap, newWidth, newHeight, true); 

這會壓縮圖像,使圖像更小的尺寸,你只是還需要給新的高度和寬度按您的要求。

0

的ONCLICK按鈕調用的方法將圖像保存到SD卡:

SaveImage(bitmap); 

保存圖片到SD卡:

private void SaveImage(Bitmap finalBitmap) { 

    String root = Environment.getExternalStorageDirectory().toString(); 
    File myDir = new File(root + "/demo_images");  
    myDir.mkdirs(); 
    Random generator = new Random(); 
    int n = 10000; 
    n = generator.nextInt(n); 
    fname = "Image-"+ n +".jpg"; 
    File file = new File (myDir, fname); 
// Below code will give you full path in TextView 

> txtPath1.setText(file.getAbsolutePath()); 

    if (file.exists()) file.delete(); 
    try { 
     FileOutputStream out = new FileOutputStream(file); 
     finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); 
     out.flush(); 
     out.close(); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

對於從SD卡獲取圖像:

Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath()); 
imageview.setImageDrawable(bitmap); 

用於存儲圖像到內部存儲器:

Saving and Reading Bitmaps/Images from Internal memory in Android