2011-09-07 133 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