This code gives me image taken from android camera ,however,its size and resolution format of the thumnail.
Bitmap photo = (Bitmap) data.getExtras().get("data");
How can I get the original image with the original size and resolution
Thank you
Bitmap photo = (Bitmap) data.getExtras().get("data");
this code gives you only thumnail image.To get the original image u need to use EXTERNAL_STORAGE which image saved there. (Code is something like this)
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
For more information take a look at here
Create a Temp File in externalCacheDir and put the URI in your Intent which starts the camera, after image shooting the image is stored in that file.
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File tempCaptureFile = ImageAccessor.createTempFile(getActivity(), TEMP_CAPTURE_FILE_NAME);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempCaptureFile));
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
getActivity().startActivityForResult(takePictureIntent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
ImageAccessor is just a helper class to create a File in externalCacheDir.
Bitmap photo = (Bitmap) data.getExtras().get("data");
this line only return thumbnal image reffer bellow link
android camera intent
Related
I know how to open gallery intent and to display in the imageview.
But I am facing problem in selecting image automatically in oncreate method and display in the imageview.
I have an image in gallery folder with name "myfile.jpg"
Can anyone guide me how to do it without openting gallery intent.
Thank you in advance
Here is solution :
ImageView image = (ImageView)findViewById(R.id.myImage);
File root = Environment.getExternalStorageDirectory();
String path = root.getAbsolutePath();
path = path + File.separator + "myfile.jpg"; //where you image file located
Bitmap myBitmap = BitmapFactory.decodeFile(path);
image.setImageBitmap(myBitmap);
I am trying to store an image file in Parse.com for use as a profile photo.
I have a function used to capture the image:
private void captureImage() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
// start the image capture Intent
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
According to Parse documentation, I need to have the data in byte[] form and then create a ParseFile with it. So, I have this:
byte[] data = fileUri.getBytes();
// Save image to Parse
photoFile = new ParseFile("profile_photo.jpg", data);
I am getting an error: cannot resolve method getBytes. Not entirely sure if I am missing an import, or if I am approaching this the entirely wrong way. How can I convert a captured image file to byte form so I can create a ParseFile?
I'm having a bytearray of an image. I need to display the image using device image broswer.
I used this code to open an image which is having the URI which is working fine
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
Uri u = Uri.fromFile(destinationFile);
intent.setDataAndType(u, "image/*");
startActivity(intent);
Problem I dont have an URI i just having an image byte array. So how can i acheive this
Please help me
Thanks
Hope this code will help you:
Bitmap bmp = BitmapFactory.DecodeByteArray(data, 0, data.Length);
imageview.SetImageBitmap(bmp);
Source: conversion of byte array to image
In my application I use the camera to take photos.
I use this code to start the camera Activity:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
timeStamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
File file = new File(directory, timeStamp+".png"); //name
Uri outputFileUri1 = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri1);
startActivityForResult(intent, CAMERA_RESULT);
This code is working, but how can I edit the preview image (crop, rotate,...) before my main Activity gets the data in onActivityResult()?
Or how can I start the photo editor for my image from my application?
You should create a Bitmap object out of your image, then you could manipulate it.
String fooFile = "PATH TO FILE";
Bitmap bmp = BitmapFactory.decodeFile(fooFile);
here is a crop example. for more examples just Google for 'Bitmap manipulation android'
In my application I capture photo by android camera and then I want to send it to the server. For this I use Client Socket programming. I convert the capture photo into bytearray(byte[]) and then send it to the server. Every thing work perfactally.
Problem is there I am not able to send original photo to the server. Thumbnail photo is sended by the android mobile phone. But when I capture photo by the camera then original photo is there in Gallery.
How to get this original photo to use in my application?
My Code:
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra("outputFormat",Bitmap.CompressFormat.JPEG);
cameraIntent.putExtra("return-data", true);
startActivityForResult(Intent.createChooser(cameraIntent, "Select Picture"),
CAMERA_REQUEST);
And in onActivityResult method:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
// byte[] a = (byte[]) data.getExtras().getByteArray("data"); // I also use this but not work
ByteArrayOutputStream bos = new ByteArrayOutputStream();
photo.compress(CompressFormat.JPEG, 100, bos);
byte[] bitmapdata = bos.toByteArray();
}
}
in bitmapdata photo is there but compressed photo not the original.
Some of people say that, change quality field of compress(CompressFormat.JPEG, 100, bos); in between 0 to 100 but nothing will happen.
-- >> is there any other way also to get original photo which is captured by the camera
-- >> When The photo is in folder of my computer then I read this photo in the file by giving the path. ex- File file = new File(c:\newphoto\image.jpg); . can I use this code in android to read original photo because I know the name and location of photo. If yes then what is the path to read photo in gallery. Is this work if I give path as: \DCIM\Camera\photoName.jpg.
-- >> Or some change need in my current code and it will work fine?
You are using the Intent to capture the image using ACTION_IMAGE_CAPTURE. If you normally starts your camera using Intent then it will return image as a bitmap in onActivityResult() but it will be for thumbnail purpose.
If you want to get full resolution image from the camera then you should provide a file with the intent which you are firing to start the camera activity.
You can do like below
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File out = Environment.getExternalStorageDirectory();
out = new File(out, imagename);
i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(out));
startActivityForResult(i, CAMERA_RESULT);
Here there is a MediaStore.EXTRA_OUTPUT parameter which takes a Uri of the file in which you want your camera to write a images.
For more information you can refer below example
Capture full resolution image from camera