请看这段代码。它只解码画廊图像而不是相机捕获的图像。如何filePath
在相机捕获图像代码中指定 a ,以便它解码捕获的图像并压缩它们,并且只会解码画廊图像而不是相机捕获的图像。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
if (requestCode == GALLERY_PICTURE) {
Uri uri = imageReturnedIntent.getData();
if (uri != null) {
// User had pick an image.
Cursor cursor = getContentResolver().query(uri, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);
cursor.moveToFirst();
final String imageFilePath = cursor.getString(0);
File photos = new File(imageFilePath);
yourSelectedImage = decodeFile(photos);
yourSelectedImage = Bitmap.createScaledBitmap(yourSelectedImage, 150, 150, true);
imageView1.setImageBitmap(yourSelectedImage);
cursor.close();
} else {
Toast toast = Toast.makeText(this, "No Image is selected.", Toast.LENGTH_LONG);
toast.show();
}
} else if (requestCode == CAMERA_PICTURE) {
if (imageReturnedIntent.getExtras() != null) {
// here is the image from camera
yourSelectedImage = (Bitmap)
imageReturnedIntent.getExtras().get("data");
imageView1.setImageBitmap(yourSelectedImage);
deleteLastCapturedImage();
}
}
}