i want to Imitate crop function of system Gallery as the pic http://i.6.cn/cvbnm/88/4a/be/94d8630ca9a3261154f0acf2ebd9f39d.png ,i have found the souce code ,at Gallery\src\com\android\camera , but i cannot add the edit rectangular on one pic,i know the edit rectangular is finiehed in the HighlightView.jave file.can you tell me how to add a edit rectangular on the pic,which can scale and move like edit rectangular
1.Fire the intent
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
intent.putExtra("crop", "true");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(IMAGE_PATH_TO_SAVE_CROPPED_IMAGE)));
startActivityForResult(Intent.createChooser(intent, "Select Picture"), RETURN_CODE);
2.Then in onActivityResult
Bitmap bitmap = BitmapFactory.decodeFile(IMAGE_PATH_TO_SAVE_CROPPED_IMAGE);
// bitmap will contain the cropped image
Related
I'm facing a problem that I cannot solve. I would be grateful if you could help me.
I would like to make an app that picks one or more images from the gallery, elaborates them and saves them into a folder.
The problem I have is to rotate the images correctly.
When I pick one image (see the code below), the app rotates the image correctly.
If I pick more images simultaneously (see the code below) I cannot rotate them because the value of "rotation" (see the code below) is always 0 (zero).
To pick one image from the gallery, I use the following code:
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, RESULT_LOAD_IMG);
In "OnActivityResult" I get the URI path as following:
Uri imageUri = data.getData();
To pick more images I use the following code (that doesn’t open the gallery, just the recent images, but it’s acceptable for me):
Intent intent = new Intent();
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), 1);
In "OnActivityResult" I get the URI path as following:
ClipData mClipData = data.getClipData();
and in a "for":
ClipData.Item item = mClipData.getItemAt(i);
Uri imageUri = item.getUri();
To get the image orientation I use the following code:
String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION};
Cursor cur = getApplicationContext().getContentResolver().query(imageUri, orientationColumn, null, null, null);
int orientation = -1;
if (cur != null && cur.moveToFirst()) {
orientation = cur.getInt(cur.getColumnIndex(orientationColumn[0]));
}
Note: I tried to use the “ExifInterface” class but it always returns 0 (zero) on my Samsung S7 Android 7.0.
I noticed that the method to pick one image returns a URI path like “content://media/external/images/media/imageX”, instead the method to pick more images returns a URI path like “content://com.android.providers.media.documents/document/imageX”. I don’t know if it can be the problem.
Thank you everybody in advance.
Vincenzo
I want to open device gallery except .gif images.
I tried the following code but it showing all images in gallery, let me help
Intent pickPhoto = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
if(Build.VERSION.SDK_INT >21){
pickPhoto.setType("image/*");
pickPhoto.setAction(Intent.ACTION_GET_CONTENT);
}
startActivityForResult(pickPhoto, PICK_FROM_GALLERY);
To open the device gallery except for .gif images, you need to set the supported mimeTypes for the gallery intent i.e., image types you need to pick from the gallery like png, jpg, jpeg, etc.
Intent intent = new Intent();
intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
String[] mimeTypes = {"image/png", "image/jpg", "image/jpeg"};
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
startActivityForResult(intent, REQUEST_GALLERY);
Getting an image from the Gallery with
Intent intentGallery = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intentGallery, CHOOSE_PICTURE);
and
Uri targetUri = data.getData();
Log.v(LOG_TAG,"Data achieved from gallery: "+ targetUri);
results in content://com.android.sec.gallery3d.provider/picasa/ if the user selected a Picasa image.
This solution is not good for me, because i don't want to use internet.
So, there is a way to pick only the local picasa image thumbnail from gallery?
I want to upload photos from Android's mobile gallery from my app. How can I do that?
You should use the MediaStore to be able to get pictures from the gallery:
http://developer.android.com/reference/android/provider/MediaStore.Images.Media.html
Edit:You can get the image with this:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, 1);
And you get the bitmap with this in your onActivityResult :
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getActivity()
.getContentResolver(), data.getData());
I am developing an app in which i need to import images from the default gallery to the storage in sd card that I use for the app. Is it possible?
You can use an Intent to have the user pick an image from the default gallery.
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
photoPickerIntent.setType("image/*");
Uri path = getTempUri("/mnt/sdcard/yourfolder");
photoPickerIntent.putExtra(MediaStore.EXTRA_OUTPUT, path);
photoPickerIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
startActivityForResult(photoPickerIntent, filenameInt);
This will save the image picked by the user to the path you specified. There are some more options like cropping and scaling:
photoPickerIntent.putExtra("crop", "true")
.putExtra("aspectX", 4)
.putExtra("aspectY", 3)
.putExtra("outputX", 800)
.putExtra("outputY", 600)
.putExtra("scale", true);
I don't know if this is exactly what you're aiming for though.