6

I am trying to crop an image I have used the code below

Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); i.putExtra("crop", "true");
startActivityForResult(i, 1);

But i have to do crop image without using Intent. And also have to customize the croping UI. please help me out how to do that.

I am not supposed to use new Intent("com.android.camera.action.CROP");
with Thanks
Vikash

Vikash Kumar
  • 621
  • 2
  • 6
  • 21

3 Answers3

8

Here is a sample project that Works same like Default Crop Intent of Android. CropImage If you really looking to try what you said,First look in to this link,Hope it may help you to find your way.

MKJParekh
  • 34,073
  • 11
  • 87
  • 98
  • the link to the code you have given is not working. but i got some idea about CropImage.java class. Thanks – Vikash Kumar Nov 16 '11 at 06:58
  • ya i have installed the project but after taking picture from android camera then press ok button it is giving Force Close. I am getting into the code, if i have any problem i will get back to you. Thanks – Vikash Kumar Nov 16 '11 at 07:07
  • strange..cause the same works fine in all my devices thats why i told you so confidently..anyways,,,you can send me logcats for the errors and i will try to help if i could..In that take the whole package to your project call CropImage.java with passing your bitmap and get that bitmap in cropimage.java and replace necessary – MKJParekh Nov 16 '11 at 07:21
  • this is the errer in Logcat11-16 14:02:52.155: VERBOSE/camera(349): mJpegCallbackFinishTime = 6ms 11-16 14:02:56.125: ERROR/AndroidRuntime(340): FATAL EXCEPTION: main 11-16 14:02:56.125: ERROR/AndroidRuntime(340): java.lang.RuntimeException: Unable to resume activity {com.droid4you.util.cropimage/com.droid4you.util.cropimage.MainActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=null} to activity {com.droid4you.util.cropimage/com.droid4you.util.cropimage.MainActivity}: java.lang.NullPointerException – Vikash Kumar Nov 16 '11 at 08:34
  • where you are testing this? if it's 2.1 change it to higher or lower any..and if possible test in device..this error i seen while taking photo and intent failed sometime with passing extra parameters to it. – MKJParekh Nov 16 '11 at 09:07
  • without this inbilt apps it`s possible to crop the image – Zala Janaksinh Aug 07 '12 at 11:08
  • @ZalaJanaksinh bapu, are you asking a question or telling it? – MKJParekh Aug 07 '12 at 11:44
  • Dear i asking question.it`s possible i want to do this and my code is here if have any idea please help me.http://stackoverflow.com/questions/11840811/how-to-get-select-area-which-cover-by-canvas-in-android thank in advance dear – Zala Janaksinh Aug 07 '12 at 11:48
  • This code needs to be modified a little, because the newest Camera application does not seem to work with being supplied a file path to save the captured image, instead it returns a content URI which needs to be read out of instead of trying to open a file. Other than that, it's a great library and works wonders. – Elad Nava Sep 15 '12 at 18:46
  • 1
    @Vikash Kumar I met the same problem and solved it by changing the code of MainActivity. The problem was found on SAMSUNG devices, both 2.2 and 4.1. Here is my solution: add the following code to the end of the onCreate function: mImageCaptureUri = Uri.parse("file:///sdcard/temp.jpg"), and delete the initialization code for mImageCaptureUri in the doTakePhotoAction function. – Lei Guo Mar 13 '13 at 02:56
  • Find the reason finally. Because the SAMSUNG phone destroy the MainActivity and create it again when returning from the Take Picture Activity, the mImageCaptureUri is null, leads to the NullPointerException. Some phones won't destroy MainActivity when returning, so the mImageCaptureUri has its value and the program works well. – Lei Guo Mar 13 '13 at 04:21
  • @Leoguo I think you have worked enough on this topic, guess more than my self, So I suggest you to take some time and write a complete good answer and post it below as another answer, that will help us all in a better way..good work.. :) – MKJParekh Mar 13 '13 at 09:33
1

You can use createBitmap() to extract a subset of a current bitmap.

Kurtis Nusbaum
  • 30,445
  • 13
  • 78
  • 102
1

take a look at the following link. Should provide a good stepping stone to step up a ui with pinch to zoom and scroll and finally once you have what you want you can use a second view as your crop region. depends on what your looking for otherwise createBitmap option also works. http://blog.sephiroth.it/2011/04/04/imageview-zoom-and-scroll/

 View view = findViewById(R.id.crop_region);
 view.setDrawingCacheEnabled(true);
 view.buildDrawingCache();
 Bitmap cropBitmap = view.getDrawingCache();
caguilar187
  • 753
  • 3
  • 10
  • this link is for touch zoom and scroll behavior. – Vikash Kumar Nov 16 '11 at 06:59
  • am aware but i was assuming you would be allowing your users select the area they want to crop by using some form of bounding box. which is why i provided that and the above code which creates a bitmap of all the content within a bounding frame/view. – caguilar187 Nov 16 '11 at 07:06