我设法以编程方式从相机拍摄照片,然后将其显示在图像视图上,然后在按下按钮后将其保存在图库中。它有效,但问题是保存的照片分辨率低.. 为什么?!
我用这段代码拍了照片:
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) {
}
});
}
我真的不明白为什么它在保存时会失去这么多质量。请帮忙吗?谢谢..