2

am working with wallpaper app. In this i add some images in drawable folder and displays in gridview. When user selects one, i need to crop that image and set as wallpaper as per in android default wallpaper setting. Searching a lot but all those contains croping image from sdcard. Please give me any suggestion.

Thanks.

Shalini
  • 1,733
  • 4
  • 17
  • 31
  • What did you done? put you sample code. – Aerrow Jun 22 '12 at 09:14
  • I just need suggestion that it is possible to crop the image from drawable folder, not from sdcard. If possible, need sample code. – Shalini Jun 22 '12 at 09:16
  • See here http://stackoverflow.com/questions/3035692/how-to-convert-a-drawable-to-a-bitmap and then here http://stackoverflow.com/questions/6908604/android-crop-center-of-bitmap – vasart Jun 22 '12 at 09:16
  • @Shalini: off-course, there are lot of post in StackOverflow – Aerrow Jun 22 '12 at 09:17
  • No i ask the crop of image by user touch as per in android wallpaper setting – Shalini Jun 22 '12 at 09:18
  • Yes you can do, For you information after the crop process, you may set the image as wallpaper it fit to all screens.(number of screen widgets in that device, so the image look like stretched) – Aerrow Jun 22 '12 at 09:20

1 Answers1

1

try this way:

Uri imgUri=Uri.parse("android.resource://your.package.name/"+R.drawable.image);
 Intent intent = new Intent("com.android.camera.action.CROP");  
        intent.setDataAndType(imgUri, "image/*");  
        intent.putExtra("crop", "true");  
        intent.putExtra("aspectX", 1);  
        intent.putExtra("aspectY", 1);  
        intent.putExtra("outputX", 80);  
        intent.putExtra("outputY", 80);  
        intent.putExtra("return-data", true);
        startActivityForResult(intent, 1);
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
  • @Shalini: use this answer, this will call the default crop functionality of the device. – Aerrow Jun 22 '12 at 09:22
  • Hi imran, It contains lot of lines when post my code. I use your code in button click but it force close and the error in logcat says"android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.android.camera.action.CROP dat=android.resource://com.cutewallpaper/2130837517 typ=image/* (has extras) }" – Shalini Jun 22 '12 at 09:42
  • Is there anyway to pass bitmap to Uri imgUri=Uri.parse("android.resource://your.package.name/"+R.drawable.image); – Shalini Jun 23 '12 at 07:01
  • Sorry @Shalini for late response can u plz try https://sites.google.com/site/imrankhanandroid/TestCrop.rar?attredirects=0&d=1 and let me known this is right way to do – ρяσѕρєя K Jun 23 '12 at 08:52
  • it have try it after putting image in asset ,row,and android drawable folders but not working only way to work create temp image on sdcard – ρяσѕρєя K Jun 23 '12 at 09:15
  • ya great. Thank you so much. it works when create temp image in sdcard. – Shalini Jun 23 '12 at 09:19
  • Thanks @Shalini .if u have any other issue then comment me.:-) – ρяσѕρєя K Jun 23 '12 at 09:22
  • hi i want crop the image using Canvas.i draw one canvas over imageView then how to crop this.please five me any idea i am in trouble.my question is here.http://stackoverflow.com/questions/11840811/how-to-get-select-area-which-cover-by-canvas-in-android please check this and give any idea thank in advance – Zala Janaksinh Aug 07 '12 at 10:33