1

我设法以编程方式从相机拍摄照片,然后将其显示在图像视图上,然后在按下按钮后将其保存在图库中。它有效,但问题是保存的照片分辨率低.. 为什么?!

我用这段代码拍了照片:

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); 

然后我使用以下方法将照片保存在 var 上:

  protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
        if (requestCode == CAMERA_PIC_REQUEST) {  
            thumbnail = (Bitmap) data.getExtras().get("data"); 
        }  
    } 

然后在图像视图上显示它之后,我使用这个功能将它保存在画廊中:

public void SavePicToGallery(Bitmap picToSave, File savePath){


String JPEG_FILE_PREFIX= "PIC";
String JPEG_FILE_SUFFIX= ".JPG";


String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = JPEG_FILE_PREFIX + timeStamp + "_";
File filePath = null;
try {
    filePath = File.createTempFile(imageFileName, JPEG_FILE_SUFFIX, savePath);
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
FileOutputStream out = null;
try {
    out = new FileOutputStream(filePath);
} catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
picToSave.compress(CompressFormat.JPEG, 100, out);
try {
    out.flush();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
try {
    out.close();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

//Add the pic to Android Gallery
String mCurrentPhotoPath = filePath.getAbsolutePath();

MediaScannerConnection.scanFile(this,
        new String[] { mCurrentPhotoPath }, null,
        new MediaScannerConnection.OnScanCompletedListener() {
        public void onScanCompleted(String path, Uri uri) {

        }
});


}

我真的不明白为什么它在保存时会失去这么多质量。请帮忙吗?谢谢..

4

2 回答 2

0

您在 ImageView 中显示的照片是缩略图:

data.getExtras().get("data");

你在调用方法吗:

public void SavePicToGallery(Bitmap picToSave, File savePath)

用缩略图?

在这里你有描述做你想做的所有步骤:http: //developer.android.com/training/camera/photobasics.html

于 2013-10-22T15:50:48.473 回答
0

data.getExtras().get("data") 只获取缩略图。

要正确执行此操作,您必须声明全局 uri 变量

 Uri imageCapturedUri ;


 Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            imageCaptureUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageCaptureUri);
 startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); 

  protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
     if (requestCode == CAMERA_PIC_REQUEST) {  

          // mImageCaptureUri is your Uri
      }  
  } 
于 2013-10-22T15:54:51.593 回答