I am getting low quality picture in max devices but in Redmi 1s I am getting dark or black image after capturing from camera.
I want to do 3 jobs
Capture image from camera
Capture original or high quality image
Set that as background of my device
My Code is:
final int CAMERA_CAPTURE = 1;
final int CROP_PIC = 2;
private Uri picUri;
Bitmap setphoto;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.camera);
Button captureBtn = (Button) findViewById(R.id.camera);
captureBtn.setOnClickListener(this);
((Button) findViewById(R.id.setimage))
.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Toast var;
if(setphoto != null)
{
Bitmap image = setphoto;
WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext());
try {
myWallpaperManager.setBitmap(image);
} catch (IOException e) {
// TODO Auto-generated catch block
var = Toast.makeText(Camera.this, "Home Screen Not Changed",Toast.LENGTH_SHORT);
var.show();
e.printStackTrace();
}
var = Toast.makeText(Camera.this, "Home Screen Changed",Toast.LENGTH_SHORT);
var.show();
}
else {
var = Toast.makeText(Camera.this, "Pick Image From Gallery",Toast.LENGTH_SHORT);
var.show();
}
}});
};
public void onClick(View v) {
if (v.getId() == R.id.camera) {
try {
// use standard intent to capture an image
Intent captureIntent = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE);
// we will handle the returned data in onActivityResult
startActivityForResult(captureIntent, CAMERA_CAPTURE);
} catch (ActivityNotFoundException anfe) {
// Toast toast = Toast.makeText(this, "This device doesn't support the crop action!",
// Toast.LENGTH_SHORT);
//toast.show();
}
} }
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == CAMERA_CAPTURE) {
// get the Uri for the captured image
picUri = data.getData();
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setType("image/*");
List<ResolveInfo> list = getPackageManager().queryIntentActivities( intent, 0 );
int size = list.size();
if (size != 0) {
performCrop();
//Toast.makeText(this, "Can not find image crop app", Toast.LENGTH_SHORT).show();
}
else
{
Bundle extras = data.getExtras();
// get the cropped bitmap
Bitmap thePic = extras.getParcelable("data");
setphoto = thePic;
ImageView picView = (ImageView) findViewById(R.id.image);
picView.setImageBitmap(thePic);
}
}
// user is returning from cropping the image
else if (requestCode == CROP_PIC) {
// get the returned data
Bundle extras = data.getExtras();
// get the cropped bitmap
Bitmap thePic = extras.getParcelable("data");
setphoto = thePic;
ImageView picView = (ImageView) findViewById(R.id.image);
picView.setImageBitmap(thePic);
}
}
}
/**
* this function does the crop operation.
*/
private void performCrop() {
// take care of exceptions
try {
// call the standard crop action intent (the user device may not
// support it)
Intent cropIntent = new Intent("com.android.camera.action.CROP");
// indicate image type and Uri
cropIntent.setDataAndType(picUri, "image/*");
// set crop properties
cropIntent.putExtra("crop", "true");
// indicate aspect of desired crop
cropIntent.putExtra("aspectX", 3);
cropIntent.putExtra("aspectY", 4);
// indicate output X and Y
cropIntent.putExtra("outputX", 800);
cropIntent.putExtra("outputY", 800);
// retrieve data on return
cropIntent.putExtra("return-data", true);
// start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, CROP_PIC);
}
// respond to users whose devices do not support the crop action
catch (ActivityNotFoundException anfe) {
Toast toast = Toast
.makeText(this, "This device doesn't support the crop action!", Toast.LENGTH_SHORT);
toast.show();
}
}
}
Try this for high quality
Uri mHighQualityImageUri = generateTimeStampPhotoFileUri();
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mHighQualityImageUri);
startActivityForResult(intent, REQUEST_CODE_HIGH_QUALITY_IMAGE);
And this:
private Uri generateTimeStampPhotoFileUri() {
Uri photoFileUri = null;
File outputDir = getPhotoDirectory();
if (outputDir != null) {
Time t = new Time();
t.setToNow();
File photoFile = new File(outputDir, System.currentTimeMillis()
+ ".jpg");
photoFileUri = Uri.fromFile(photoFile);
}
return photoFileUri;
}
Note:
Simple thing you need to add
intent.putExtra(MediaStore.EXTRA_OUTPUT, mHighQualityImageUri);
In your code following part:
Uri mHighQualityImageUri = generateTimeStampPhotoFileUri();
// use standard intent to capture an image
Intent captureIntent = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE);
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mHighQualityImageUri);
// we will handle the returned data in onActivityResult
startActivityForResult(captureIntent, CAMERA_CAPTURE);
Related
I want to pick image from the gallery and use it in my App as Profile Picture. So far I've tried this.
Here's my InfoGet class. The loadImagefromGallery gets called on click.
public void loadImagefromGallery(View view) {
/* Intent galleryIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD);*/
Intent gallery_Intent = new Intent(getApplicationContext(), GalleryUtil.class);
startActivityForResult(gallery_Intent, GALLERY_ACTIVITY_CODE);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == GALLERY_ACTIVITY_CODE) {
if(resultCode == Activity.RESULT_OK){
String picturePath = data.getStringExtra("picturePath");
//perform Crop on the Image Selected from Gallery
performCrop(picturePath);
}
}
if (requestCode == RESULT_CROP ) {
if(resultCode == Activity.RESULT_OK){
Bundle extras = data.getExtras();
Bitmap selectedBitmap = extras.getParcelable("data");
// Set The Bitmap Data To ImageView
pro.setImageBitmap(selectedBitmap);
pro.setScaleType(ImageView.ScaleType.FIT_XY);
}
}
}
private void performCrop(String picUri) {
try {
//Start Crop Activity
Intent cropIntent = new Intent("com.android.camera.action.CROP");
// indicate image type and Uri
File f = new File(picUri);
Uri contentUri = Uri.fromFile(f);
cropIntent.setDataAndType(contentUri, "image/*");
// set crop properties
cropIntent.putExtra("crop", "true");
// indicate aspect of desired crop
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
// indicate output X and Y
cropIntent.putExtra("outputX", 280);
cropIntent.putExtra("outputY", 280);
// retrieve data on return
cropIntent.putExtra("return-data", true);
// start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, RESULT_CROP);
}
// respond to users whose devices do not support the crop action
catch (ActivityNotFoundException anfe) {
// display an error message
String errorMessage = "your device doesn't support the crop action!";
Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
toast.show();
}
}
And here's my GalleryUtil code
public class GalleryUtil extends Activity {
private final static int RESULT_SELECT_IMAGE = 100;
public static final int MEDIA_TYPE_IMAGE = 1;
private static final String TAG = "GalleryUtil";
String mCurrentPhotoPath;
File photoFile = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try{
//Pick Image From Gallery
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_SELECT_IMAGE);
}catch(Exception e){
e.printStackTrace();
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode){
case RESULT_SELECT_IMAGE:
if (resultCode == Activity.RESULT_OK && data != null && data.getData() != null) {
try{
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
//return Image Path to the Main Activity
Intent returnFromGalleryIntent = new Intent();
returnFromGalleryIntent.putExtra("picturePath",picturePath);
setResult(RESULT_OK,returnFromGalleryIntent);
finish();
}catch(Exception e){
e.printStackTrace();
Intent returnFromGalleryIntent = new Intent();
setResult(RESULT_CANCELED, returnFromGalleryIntent);
finish();
}
}else{
Log.i(TAG, "RESULT_CANCELED");
Intent returnFromGalleryIntent = new Intent();
setResult(RESULT_CANCELED, returnFromGalleryIntent);
finish();
}
break;
}
}
}
I need help can anyone just make some changes in the existing code. I do not want to rebuild anything from scratch. I want to optimise this image picker before I release the next update. The Existing code work okay for devices with decent amount of RAM like 1GB or so.
Please help me.
And also explain what you did and how it works. Thanks a LOT.
I did that method read images from path and solve this issue, maybe it help you:
public static Bitmap readBitmap(Uri selectedImage, int resizeFactor)
{
Bitmap bm = null;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = resizeFactor;
AssetFileDescriptor fileDescriptor = null;
try
{
fileDescriptor = context.getContentResolver().openAssetFileDescriptor(selectedImage, "r");
} catch (FileNotFoundException e)
{
e.printStackTrace();
} finally
{
try
{
bm = BitmapFactory.decodeFileDescriptor(fileDescriptor.getFileDescriptor(), null, options);
fileDescriptor.close();
} catch (IOException e)
{
e.printStackTrace();
}
}
return bm;
}
The atributes are Uri selectedImage and int resizeFactor;
on selectedImage you need to put a Path from image and on resizeFactor put a int number, Normally I use number 10, try with that or try with another one (down/up)
Now if you want to put on ImageView you can use that.
ImageView.setImageBitmap(readBitmap(Path, 10));
Later you need clear Bitmap content to avoid OutOfMemory, use that method:
public static void clearBitmap(Bitmap bm)
{
bm.recycle();
}
I do a crop on an image after it is captured by my camera - all working.
The image appears in my gallery all cropped and lovely - all working.
I assign the image after calling crop to a imageview using the uri - not working
Heres my code, i think my issue is that the uri is pointing to the old uncropped image in \storage\emulator\0... and the cropped goes straight to my gallery. How can i get cropped úí and the cropped image is in my gallery - How do i get the cropped image into my imageView
code:
private static final int PICK_IMAGE = 0;
private static final int PICK_IMAGE_FROM_GALLERY = 1;
private static final int CROP_IMAGE = 2;
private Uri uri;
.
.
.
btnPhotoCamera.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent camera=new Intent();
camera.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
//camera.putExtra("crop", "true");
File f=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
uri = Uri.fromFile(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),"myFile.jpg"));
camera.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(camera, PICK_IMAGE);
}
});
private void performCrop(Uri picUri)
{
//NEXUS 5 OS 5 is example of this branch
// take care of exceptions
try {
// call the standard crop action intent (the user device may not
// support it)
Intent cropIntent = new Intent("com.android.camera.action.CROP");
// indicate image type and Uri
cropIntent.setDataAndType(uri, "image/*");
// set crop properties
cropIntent.putExtra("crop", "true");
// // indicate aspect of desired crop
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
// // // indicate output X and Y
// retrieve data on return
cropIntent.putExtra("return-data", true);
// start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, CROP_IMAGE);
}
// respond to users whose devices do not support the crop action
catch (ActivityNotFoundException anfe)
{//NOT TESTED AS HW DOES NOT GO HERE
Toast toast = Toast.makeText(this,"This device doesn't support the crop action! Exception: " + anfe.toString(),Toast.LENGTH_SHORT);
toast.show();
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
// TODO Auto-generated method stub
if (resultCode==RESULT_OK )
{
if(requestCode == PICK_IMAGE) //reply from camera
{
performCrop(uri); //crop the picture
}
if(requestCode == CROP_IMAGE) //reply from crop
{
Bitmap bmp = getBitmap(uri);
imgView.setImageBitmap(bmp);
}
}
}
private Bitmap getBitmap(Uri bitmap_uri) {
InputStream is=null;
try
{
is = this.getContentResolver().openInputStream(bitmap_uri);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
return BitmapFactory.decodeStream(is);
}
}
Crop result will be in the date extra in onActivityResult as below:
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if(requestCode == CROP_IMAGE && resultCode == RESULT_OK) //reply from crop
{
Bundle extras = data.getExtras();
if(extras != null ) {
Bitmap photo = extras.getParcelable("data");
FileOutputStream fOut = new FileOutputStream(tmpFile);
photo.compress(Bitmap.CompressFormat.JPEG, 75, fOut);
//etc
}
}
}
Its open the "choose from galary" option but i dont want this. I want directly showing the croping option on image. I have used intent for that
// Crop.java
private String defaultImagePath;
final int PIC_CROP = 1;
private Uri mCropImagedUri;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.crop);
cropImage = (ImageView) this.findViewById(R.id.imageView4);
seekBarCrop = (SeekBar) findViewById(R.id.seekBarCrop);
Bundle b = getIntent().getExtras();
String imagePath = b.getString("imagePath");
defaultImagePath = imagePath;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
bitmap = BitmapFactory.decodeFile(imagePath, options);
cropImage.setImageBitmap(bitmap);
cropImageActivity(defaultImagePath, cropImage);
}
private void cropImageActivity(String path, View cropImage) {
try {
mCropImagedUri = Uri.parse(path);
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(mCropImagedUri, "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("scale", true);
cropIntent.putExtra("outputX", 500);
cropIntent.putExtra("outputY", 500);
cropIntent.putExtra("return-data", false);
// start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, PIC_CROP);
} catch (ActivityNotFoundException anfe) {
// display an error message
String errorMessage = "Whoops - your device doesn't support the crop action!";
Toast toast = Toast
.makeText(this, errorMessage, Toast.LENGTH_SHORT);
toast.show();
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PIC_CROP) {
if (data != null) {
// get the returned data
Bundle extras = data.getExtras();
// get the cropped bitmap
Bitmap selectedBitmap = extras.getParcelable("data");
cropImage.setImageBitmap(selectedBitmap);
}
}
}
I am passing image url to the following method
private void performCrop(Uri imageUri){
try {
Intent intent = new Intent("com.android.camera.action.CROP");
// intent.setType("image/*");
intent.setDataAndType(imageUri, "image/*");
List<ResolveInfo> list = getActivity().getPackageManager().queryIntentActivities( intent, 0 );
int size = list.size();
if (size >= 0) {
intent.setData(imageUri);
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 0);
intent.putExtra("aspectY", 0);
intent.putExtra("outputX", 150);
intent.putExtra("outputY", 150);
intent.putExtra("scale", true);
intent.putExtra("scaleUpIfNeeded", true);
intent.putExtra("return-data", true);
Intent i = new Intent(intent);
ResolveInfo res = list.get(0);
i.setComponent( new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
System.out.println("before startActivityForResult");
try{
startActivityForResult(i, 2);
}catch(Exception e){
e.printStackTrace();
}
}
}
catch(ActivityNotFoundException anfe){
String errorMessage = "Whoops - your device doesn't support the crop action!";
//Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
//toast.show();
}
}
some of images are cropped but some image are not. When I crop image then my app's activity is closed and application starts it's previous or launcher activity so what is the problem??
the main issue is I am not getting any warning or error in log cat, and when I debug it the the till "System.out.println("before startActivityForResult");" the program excutes, that means it does not goes in or calling onActivityResult().
here is onActivityResult method
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(requestCode ==2 && resultCode == getActivity().RESULT_OK){
System.out.println("inside logic...");
try{
if (data != null) {
// get the returned data
Bundle extras = data.getExtras();
// get the cropped bitmap
Bitmap bmp = extras.getParcelable("data");
imageView.setImageBitmap(bmp);
}
}catch(Exception e){
e.printStackTrace();
}
}
}
this code works successfully for me.try it
private static final int CAMERA_REQUEST = 1;
public static final int MEDIA_TYPE_IMAGE = 1;
final int PIC_CROP = 12;
Button btnCamera;
ImageView iv;
Uri picUri;
static File mediaFile, sendFile;
btnCamera.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
onImgProfile();
}
});
void onImgProfile() {
Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
picUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, picUri);
startActivityForResult(captureIntent, CAMERA_REQUEST);
}
private Uri getOutputMediaFileUri(int type) {
return Uri.fromFile(getOutputMediaFile(type));
}
private File getOutputMediaFile(int type) {
File mediaStorageDir = new File(
Environment.getExternalStorageDirectory(), "MyCameraApp");
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d("MyCameraApp", "failed to create directory");
return null;
}
}
// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
.format(new Date());
if (type == MEDIA_TYPE_IMAGE) {
mediaFile = new File(mediaStorageDir.getPath() + File.separator
+ "IMG_" + timeStamp + ".jpg");
} else {
return null;
}
return mediaFile;
}
#SuppressWarnings("unchecked")
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST) {
// if (Build.VERSION.SDK_INT < 19) {
try {
if (mediaFile.exists()) {
performCrop();
// new SavePhotoData().execute();
}
} catch (Exception e) {
// TODO: handle exception
}
// }
} else if (requestCode == 11) {
try {
picUri = data.getData();
Log.i("uri", "" + picUri);
performCrop();
} catch (Exception e) {
// TODO: handle exception
}
} else if (requestCode == PIC_CROP) {
// get the returned data
try {
Bundle extras = data.getExtras();
// get the cropped bitmap
Bitmap thePic = extras.getParcelable("data");
// retrieve a reference to the ImageView
// display the returned cropped image
iv.setImageBitmap(thePic);
File mediaStorageDir = new File(
Environment.getExternalStorageDirectory(),
"MyCameraApp");
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d("MyCameraApp", "failed to create directory");
}
}
// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
.format(new Date());
sendFile = new File(mediaStorageDir.getPath() + File.separator
+ "IMG_" + timeStamp + ".png");
FileOutputStream fOut = new FileOutputStream(sendFile);
thePic.compress(Bitmap.CompressFormat.PNG, 85, fOut);
fOut.flush();
fOut.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if (resultCode == 3) {
Bundle b = data.getExtras();
b.getString("msg");
}
};
private void performCrop() {
// take care of exceptions
try {
// call the standard crop action intent (the user device may not
// support it)
try {
Intent cropIntent = new Intent("com.android.camera.action.CROP");
// indicate image type and Uri
cropIntent.setDataAndType(picUri, "image/*");
// set crop properties
cropIntent.putExtra("crop", "true");
// indicate aspect of desired crop
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
// indicate output X and Y
cropIntent.putExtra("outputX", 256);
cropIntent.putExtra("outputY", 256);
// retrieve data on return
cropIntent.putExtra("return-data", true);
// start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, PIC_CROP);
} catch (Exception e) {
// TODO: handle exception
}
}
// respond to users whose devices do not support the crop action
catch (ActivityNotFoundException anfe) {
// display an error message
String errorMessage = "Whoops - your device doesn't support the crop action!";
Toast toast = Toast.makeText(getApplicationContext(), errorMessage,
Toast.LENGTH_SHORT);
toast.show();
}
}
this code works for not only kitkat but all cersion of android
Android all devices does not have a cropping intent according #CommonsWare http://commonsware.com/blog/2013/01/23/no-android-does-not-have-crop-intent.html
so better is to use libraries
some of them are:
https://github.com/jdamcd/android-crop
https://github.com/IsseiAoki/SimpleCropView
https://android-arsenal.com/details/1/3054
Hi I have this app where I allow user to take image and crop. It works on my phones but not on my Samsung Galaxy Tablet. The "Saving image" dialog just remain and not return to my app's onActivityResult... It does return if I cancel crop[
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == 1337 && resultCode == -1) {
File fi = new File("/sdcard/tmp");
// get the Uri for the captured image - NEW
try {
mImageCaptureUri = Uri
.parse(android.provider.MediaStore.Images.Media
.insertImage(getContentResolver(),
fi.getAbsolutePath(), null, null));
// Log.i("",String.valueOf(thumbnail.getHeight()));
} catch (Exception ex) {
String errorMessage = "Your device doesn't support the crop action!";
Toast toast = Toast.makeText(this, errorMessage,
Toast.LENGTH_SHORT);
toast.show();
}
performCrop();
}
if (requestCode == PIC_CROP) {
try {
final TextView imgTv = (TextView) findViewById(R.id.info);
// Bundle extras = data.getExtras();
// thumbnail = extras.getParcelable("data");
Log.i("a", "test");
// NEW
final String filePath = Environment.getExternalStorageDirectory()
+ "/temporary_holder.jpg";
thumbnail = BitmapFactory.decodeFile(filePath);
ImageView image = (ImageView) findViewById(R.id.img);
image.setImageBitmap(thumbnail);
}}
private void performCrop() {
try {
// call the standard crop action intent (the user device may not
// support it)
Intent cropIntent = new Intent("com.android.camera.action.CROP");
// indicate image type and Uri
cropIntent.setDataAndType(mImageCaptureUri, "image/*");
// set crop properties
cropIntent.putExtra("crop", "true");
// indicate aspect of desired crop
cropIntent.putExtra("aspectX", 4);
cropIntent.putExtra("aspectY", 3);
// indicate output X and Y
cropIntent.putExtra("outputX", 500);
cropIntent.putExtra("outputY", 300);
// retrieve data on return
// cropIntent.putExtra("return-data", true);
File f = new File(Environment.getExternalStorageDirectory(),
"/temporary_holder.jpg");
try {
f.createNewFile();
} catch (IOException ex) {
Log.e("io", ex.getMessage());
}
uri = Uri.fromFile(f);
cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(cropIntent, PIC_CROP);
} // respond to users whose devices do not support the crop action
catch (ActivityNotFoundException anfe) {
// display an error message
String errorMessage = "Your device doesn't support the crop action!";
Toast toast = Toast
.makeText(this, errorMessage, Toast.LENGTH_SHORT);
toast.show();
}
}
Please refer following links for better solution:
Link 1
Link 2