2

I'm using this method:

public Bitmap decodeUri(Uri selectedImage) throws FileNotFoundException {

    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(getContentResolver().openInputStream(selectedImage), null, o);

    final int REQUIRED_SIZE = 800;

    int width_tmp = o.outWidth, height_tmp = o.outHeight;
    int scale = 1;
    while (true) {
        if (width_tmp / 2 < REQUIRED_SIZE || height_tmp / 2 < REQUIRED_SIZE) {
            break;
        }
        width_tmp /= 2;
        height_tmp /= 2;
        scale *= 2;
    }

    BitmapFactory.Options o2 = new BitmapFactory.Options();
    o2.inSampleSize = scale;
    return BitmapFactory.decodeStream(getContentResolver().openInputStream(selectedImage), null, o2);
}

To decode an URI from mi camera and then send to my webserver via an HttpURLConnection object in POST headers. But my instead get my original image: enter image description here

I get a cropped image:

enter image description here

I don't know why. Perhaps my decodeURI method is wrong? Anybody know other best method to send my image compressed to my webserver?

I used right now the next way instead of my decodeUri method:

mybitMap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);

and I have the same problem. And when I tried to open the image in my webserver with Photoshop, I see an advertisement which says "This document may be damaged (the file may be truncated or incomplete). Do you want continue?" And , after continue, I see a black space in the bottom of the image...

Anybody knows why? My code:

Bitmap mybitMap = null;
   try {
      mybitMap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);

   } catch (FileNotFoundException e) {
       e.printStackTrace();
   } catch (IOException e) {
       e.printStackTrace();
   }


   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   imagen.compress(Bitmap.CompressFormat.JPEG, 100, baos);

And I send this in POST Headers:

 Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT);
14
  • Post your image width and height before and after scale. Commented Oct 3, 2015 at 8:03
  • I dont understand you. :( Mi image width and height is variable (depending of the camera resolution) Commented Oct 3, 2015 at 8:18
  • I save an base64 uri scheme of my bitmap form send to my webserver. Perhaps this is the problem? Commented Oct 3, 2015 at 8:22
  • Then why you use a scale? Commented Oct 3, 2015 at 8:48
  • 1
    Well I think my images are self explanatory :S Commented Oct 3, 2015 at 9:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.