Android take picture and get path? - android

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
...
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_PIC_REQUEST) {
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
ImageView image = (ImageView) findViewById(R.id.photoResultView);
image.setImageBitmap(thumbnail);
}
How to get image's path to string?

As it's said in the docs:
The caller may pass an extra EXTRA_OUTPUT to control where this image will be written. If the EXTRA_OUTPUT is not present, then a small sized image is returned as a Bitmap object in the extra field. This is useful for applications that only need a small image. If the EXTRA_OUTPUT is present, then the full-sized image will be written to the Uri value of EXTRA_OUTPUT.

Related

(android) taking picture without saving

I used the code below to call camera in my android app.
With the code, I could take a picture and get the absolute path of the picture.
But the problem is that the absolute path always pointed the internal storage.
That is, the phone automatically saved the picture I took and I had to erase them one by one.
I just want the absolute path so that I can turn it into a File object without saving in my storage or SD card.
Maybe, I can temporarily save it in my allocated memory.
Is there any way to do this?
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, PICK_FROM_CAMERA);
public void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
if(resultCode != RESULT_OK)
return;
if(requestCode == PICK_FROM_CAMERA){
imageUri = data.getData();
Log.d("메시지", "uri = "+imageUri);
Cursor c = this.getContentResolver().query(imageUri, null, null, null, null);
c.moveToNext();
absolutePath = c.getString(c.getColumnIndex(MediaStore.MediaColumns.DATA));
Glide.with(this).load(imageUri).into(image);
You can take a thumbnail of image without store into internal memory or SD card:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
mImageView.setImageBitmap(imageBitmap);
}
}
For full sized image you need to define shared file (for example: cache file at SD card) and put it as MediaStore.EXTRA_OUTPUT:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// camera app will save photo into sharedFileURI path
intent.putExtra(MediaStore.EXTRA_OUTPUT, sharedFileURI);
startActivityForResult(intent, PICK_FROM_CAMERA);
See Save the Full-size Photo article of official documentation for more info

How to get name of captured image in android onActivityResult

how to get image name from captured image/intent data. any one suggest me. i need through intent data only
Here is my code:
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, PIC_FROM_CAMERA);
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == RESULT_OK && data != null){
Bitmap photo = (Bitmap) data.getExtras().get("data");
}
}
AS from the Android documentation here you could not get any name for your image since android wont name for your file but you could get the time when the image was taken and the dimension of the image from This answer You could name the image by yourself and send that bitmap.

Bitmap quality is very low

I'm trying to build an app, that captures a picture and sends the picture to another activity.
I'm trying to display this picture in the second activity and apparently the quality of picture is very low.
Here is my code so far
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, PICTURE_TAKEN);
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK){
Intent canvasIntent = new Intent(this ,canvas.class);
Bundle extras = data.getExtras();
bmpCameraResult = (Bitmap)extras.get("data");
canvasIntent.putExtra("bmp_Image", bmpCameraResult);
startActivity(canvasIntent);
}
and in the canvasActivity, I'm trying to receive the bitmap in the conventional fashion and trying to display it.
Intent intent= getIntent();
Bitmap bmp = (Bitmap) intent.getParcelableExtra("bmp_Image");
ImageView iv = new ImageView(this);
iv.setImageBitmap(bmp);
setContentView(iv);
What could be the reason for this reduction of quality? What is the optimized way of getting the high quality image?
Thank You.
Did you try to set jpegQuality (setJpegQuality) in your Camera Parameters (Camera.Parameters) as you can read here: Camera Feature Documentation?
I think you should also read these answers about the same issue:
Android: Not able to get original photo captured by camera (Able to read compress photo only)
Low picture/image quality when capture from camera

Intent pick Image From Camera compressed or with lower resolution or dimension

I'm using an intent to get an image from Camera and then I should use the data returned from intent in my Activity to display the image in an ImageView.
I want to ask if I can ask to the system to get a lower resolution or dimension image adding to the intent some putExtra(..., ...) options, so I can avoid to compress bitmap and implement all the code (I'm sure system knows better than me how to do :) ).
I hope my request is clear and someone could help me!
Sorry for my english - Regards from Italy
You can get a thumbnail of the image taken by using data.getExtras().get("data");:
final static int CAMERA_PIC_REQUEST = 1; // any int value you want
Intent mCameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(mCameraIntent, CAMERA_PIC_REQUEST);
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
switch (requestCode) {
case CAMERA_PIC_REQUEST:
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
// your ImageView
photoImage.setImageBitmap(thumbnail);
break;
}
}
}
No, you can't ask the camera to do this unfortunately. You have to get the bitmap and then sort it out yourself. See http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

Take photo and save original size

How can get photo from intent
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
in onActivityResult not in URI format but JPG,PNG orginal size and save it gallery.
Need JPG,PNG because after shot I adding watermark on it.
I don't know why after bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); returned photo size from 2048x1536 is 256x192.
For saving the image in the gallery you have send a broadcast as shown in the code sample below.
If you need the image with orignal sizes you could simply catch the uri and set it to a ImageView directly. Although it is a good practice to scale it down and use a smaller version of your bitmap to avoid the OutOfMemory Exception.
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if(requestCode==CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE){
if(resultCode==RESULT_OK){
saveToGallery(mImageUri);
yourImageView.setImageURI(mImageUri);
}
}
}
public void saveToGallery(Uri uri){
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,uri));
}

Categories

Resources