Jpeg compression quality in android - android

I am launching the image capture intent to take a picture, adding a uri so the picture is tiny. My problem is I want to set the output jpeg-quality before I start the activity.
ContentValues vals = new ContentValues();
vals.put(Media.DISPLAY_NAME, "test title");
vals.put(Media.MIME_TYPE, "image/jpeg");
Uri imageFileUri = context.getContentResolver()
.insert(Media.EXTERNAL_CONTENT_URI, vals);
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
context.startActivityForResult(i, CameraImportActivity.CAMERA_REQUEST);
I suppose I could downsample after the picture is taken, but if I can request the activity do it for me I would like to do so.
As bonus questions, how do I change the album they get saved to in the gallery, and how do I prevent the camera activity from saving a copy in the default location (on my phone it is "photos")

Related

Getting image orientation picking multiple images from gallery

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

Save image from custom camera in specific URI

I am receive an URI from my Activity. I want to be able to save a picture from my Custom Camera into that specific location, I don't know how to achieve that. Can I get some help?
I see how to save an image from the Google developer website but they create a folder, name the picture with date and etc. I have an URI which contains all the information. All I need to do is to save a picture in that URI.
Initially, I am trying to achieve manually what the camera intent does when you add this extra:
intent.putExtra(MediaStore.EXTRA_OUTPUT, URI_GOES_HERE);
Here is the code in the current Activity where the URI is passed to my Custom Camera as an Extra:
String filename = System.currentTimeMillis() + ".jpg";
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, filename);
preDefinedCameraUri = getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
values);
Log.d("Predefined URI:","" + preDefinedCameraUri);
intent.putExtra(MediaStore.EXTRA_OUTPUT, preDefinedCameraUri);
How do I save the picture in that extra?

Getting photo information from camera intent

I am having a very difficult time with the camera intent and trying to get data about the photo that was just taken
I launch the camera like this
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
File output = new File(dir, "IMG_" + timeStamp + ".jpg");
photoUri = Uri.fromFile(output);
startActivityForResult(camera, CAMERA_REQUEST);
in my onActivityResult the intent is null so I cannot use anything there to get the Uri but doing this.
Bitmap photo = MediaStore.Images.Media.getBitmap(getContentResolver(),photoUri);
gets the photo just fine. What I want to do is get information about the photo Latitude,Longitude,time taken etc so I tried this
MediaStore.Images.Media.query(getContentResolver(),photoUri,null,null,null,null);
but the cursor is always returned as null so it obviously cannot find the uri. It seems that the image is not getting out into the MediaStore provider. How can I get the data from the photo just taken?

How to create camera button that stores images to gallery?

How would I correctly get a buttons intent to take a picture and store that image in the phones gallery? So far i have a button which is in a case structure that says :
else if (v.getId() == R.id.button5)//camera
{
Intent c = new Intent( MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(c,1);
}
what should my onActivityResult look like since i am just storing that image to the gallery?
would i have to use something as bundle extras = data.getExtras();?
This answer may be your problems solution. But data.getExtras() returns null in some cases and unfortunately I have not detected all of these cases yet. For example data.getExtras() worked fine on android 2.3 HTC Evo 3D but on android 2.3 Samsung Galaxy SII, it returned null. Hope this helps.
First, you have to call your startActivityForResult() method like the following:
Uri imageFileUri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, new ContentValues());
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
startActivityForResult(i, CAMERA_RESULT);
And in the implementation of startActivityForResult() method you have to write the following:
// Save the name and description of an image in a ContentValues map.
ContentValues contentValues = new ContentValues(3);
contentValues.put(Media.DISPLAY_NAME, "This is a test title");
contentValues.put(Media.DESCRIPTION, "This is a test description");
contentValues.put(Media.MIME_TYPE, "image/jpeg");
// Add a new record without the bitmap, but with some values set.
// insert() returns the URI of the new record.
Uri imageFileUri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI,contentValues);

Specify the album of a recorded video in Android

I am trying to record a video in Android using the MediaStore.ACTION_VIDEO_CAPTURE intent. I can record the video in the default library album, but I cannot store anywhere else. I have tried to use the intent parameter EXTRA_MEDIA_ALBUM:
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, "My app videos");
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, 0);
I have also tried to insert the video row in the MediaStore before the video itself.
ContentValues videoValues = new ContentValues();
videoValues.put(MediaStore.Video.Media.TITLE, "My app video at" + System.currentTimeMillis());
videoValues.put(MediaStore.Video.Media.ALBUM, "My app videos");
Uri videoUri= getContentResolver().insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoValues);
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, 0);
And I have also tried to modify the metadata once the video is inserted, to see if it is in a different album once I open the gallery application.
protected void onActivityResult(final int requestCode, final int resultCode, final Intent dataIntent) {
...
Uri contentUri = dataIntent.getData();
ContentValues values = new ContentValues();
values.put(MediaStore.Video.Media.ALBUM, "My app videos");
int result = getContentResolver().update(contentUri, values, null, null);
'result' is 1, so the row value is actually changed, but it is not in "My app videos" album once I open it.
I have also tried different solutions explained in the Android documentation but with any Uri an IllegalArgumentException (Unknown URL file). I miss a handy method like MediaStore.Images.Media.insertImage
How have you dealt with this problem?
I have a similar problem, although my code is on two parts, one that deals Photos and the other that deals Videos, the same process and scenario gives two different results, the following thread explains more!
http://www.androidquestions.org/threads/618-Intent-doesn-t-keep-video-extras-after-capturing-the-video!?p=1761#post1761
I would be thankful if this issue has any solutions!

Categories

Resources