0

The problem here is when I send an image to server it will send very low quality image like what show in imageview, how to send more good quality even after compressing?

bitmap1 is String that will hold a bitmap after compressing

private void takeImage() {

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, selectedImage);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {


    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
        selectedImage = data.getData();
        photo = (Bitmap) data.getExtras().get("data");


        Bitmap photo = (Bitmap) data.getExtras().get("data");
        imageView.setImageBitmap(photo);

    }
}

....



ByteArrayOutputStream bao = new ByteArrayOutputStream();
            photo.compress(Bitmap.CompressFormat.JPEG, 100, bao);
            bitmap1 = Base64.encodeToString(bao.toByteArray(), Base64.DEFAULT);
majed
  • 21
  • 1
  • using `data.getExtras().get("data")` you are getting a small-size version of the photo, if you want the full-quality image, you need to provide a URI to where this photo should be saved, check this http://stackoverflow.com/questions/6001918/data-getextras-getdata-result-of-low-resolution-image-in-android – Yazan Mar 24 '16 at 09:12
  • Could you try `Bitmap.CompressFormat.PNG` instead just to be sure the loosy format is not an issue? Another solution could also come from [this post](http://stackoverflow.com/a/8419112/829610) who highlight the fact that using a **resource** will automatically set the size of the picture at the **actual screen size**. Anyway the good practice is: put the **URI** of the external picture in the extras and then load the external file from the URI stored in the extras... – Ludovic Frérot Mar 24 '16 at 09:40
  • @Yazan I used ` selectedImage = Uri.parse("file:///storage/emulated/0/sample.jpg"); intent.putExtra(MediaStore.EXTRA_OUTPUT, selectedImage);` but I get ` android.net.Uri android.content.Intent.getData() on a null object reference` my testing device is samsung galaxy – majed Mar 24 '16 at 10:51
  • you need to create the file first, then uri.parse() have a look here http://developer.android.com/training/camera/photobasics.html – Yazan Mar 24 '16 at 12:12
  • @Yazan it worked but stuck when sending image and got error of connection , I used photo = MediaStore.Images.Media.getBitmap(this.getContentResolver(),selectedImage); is there other way to take image from uri ? – majed Mar 24 '16 at 16:43

0 Answers0