Bitmap quality is very low - android

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

Related

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.

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));
}

Android take picture and get path?

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.

how to upload the image taken by calling camera activity from android phone?

hi i have an image which is taken from andorid by calling image _capture
how do i upload it to a windows server?
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, 0);
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_CANCELED) {
Toast toast = Toast.makeText(this,"camera cancelled", 10000);
toast.show();
return;
}
// lets check if we are really dealing with a picture
if (requestCode == 0 && resultCode == RESULT_OK)
{
Bundle extras = data.getExtras();
Bitmap b = (Bitmap) extras.get("data");
//setContentView(R.layout.main);
ImageView mImg;
mImg = (ImageView) findViewById(R.id.head);
mImg.setImageBitmap(b);
// save image to gallery
String timestamp = Long.toString(System.currentTimeMillis());
MediaStore.Images.Media.insertImage(getContentResolver(), b, timestamp, timestamp);
}
Here's exactly what you need to do How to send HTTP POST request and receive response?
You may take a look at this article also http://www.theserverside.com/news/1365153/HttpClient-and-FileUpload. POST upload example should help.
I'd suggest you to let the image capture activity be called from the gallery activity. The reason is you will have full sized image that'll be stored on default location, so When you finish gallery activity, you will have path to that full sized image. Intent is not designed to pass the huge file to another activity. Also I've seen that image taken by the camera (by android.media.action.IMAGE_CAPTURE) are of small sized. So refer to my blog that helps you to complete image capture and uploading tasks.

Categories

Resources