0

In my application user can select image from camera or gallery in android. After selecting image, user can also crop circular image from that original image. But after circle cropping, I am getting black rectangle image from that in HTC devices(explorer and other HTC devices). In samsung devices it works fine. I am using below code to crop image:

intent.setDataAndType(selectedImage, "image/*");
intent.putExtra("crop", "true");
intent.putExtra("outputX", 96);
intent.putExtra("outputY", 96);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
intent.putExtra("circleCrop", "true");
startActivityForResult(intent, CROP_FROM_CAMERA);

Here is my onactivityresult method where i will get cropped image:

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

    try {
    Bundle extras = data.getExtras();
    Bitmap photo = null;

    if (extras != null) {
    photo = extras.getParcelable("data");
    }
    if (photo != null) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    photo.compress(Bitmap.CompressFormat.PNG, 100, bytes);
    byte[] b = bytes.toByteArray();
    FileOutputStream out;// = new FileOutputStream(filename);
    out = openFileOutput("cropImage.png", Context.MODE_PRIVATE);
    out.write(b);
    out.close();
     pref.edit().putString(PrefernceData.PREF_IMAGE_CROP_URL,"cropImage.png").commit();
    Log.i("capute", "success after crop......");
    }catch (Exception e) {
        Toast.makeText(this, "Can not find image crop app",
        Toast.LENGTH_SHORT).show();
    }
}

In above code, when I just remove this line :intent.putExtra("circleCrop", "true"); It works fine for rectangle crop image on all HTC as well as samsung devices. But i want circle crop image only. How to resolve this problem?

j0k
  • 22,600
  • 28
  • 79
  • 90
Mihir Shah
  • 1,799
  • 3
  • 29
  • 49
  • Besides putting only image name into the Shareprefrences try to put the whole path of the image where your cropped image has been stored. – GrIsHu Apr 04 '13 at 05:43
  • Problem is not about image path, I am getting bitmap(in my case photo) itself as black image.of 96 x 96. – Mihir Shah Apr 04 '13 at 06:02

1 Answers1

0

The intent you're using isn't actually an official part of Dalvik. It works on many devices but there is no guarantee it will work the same on any/all of them. You can see some alternate libraries you may use in this blog.

Some newer alternatives can be found here .

DigCamara
  • 5,540
  • 4
  • 36
  • 47