title: crop selected image save in drawable folder
body: <p>I save few images in drawable folder &amp; save them into an array. Then i display these images in grid view list, &amp; on item click method i want to crop the selected image. When i select item is select but on activity result method gives null. But in case of gallery i am easily easily able to crop my image. below is code that i tried.</p>
  
  <p><strong>Code:</strong>   </p>
  
  <pre><code> public class SetWallpaper_Inbuilt extends Activity {
  
  Integer[] img = { R.drawable.dew_drops, R.drawable.droplets,
          R.drawable.eiffel_tower, R.drawable.whitetrees, R.drawable.windy,
          R.drawable.cold, R.drawable.thundersnow, R.drawable.snowstorms,
          R.drawable.hot };
  
  WallpaperManager wpm;
  
  GridView gridview;
  
  
  // for cropping
  final int CAMERA_CAPTURE = 1;
  final int PIC_CROP = 1;
  private Uri picUri;
  Context context;
  File f;
  
  
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.setwallpaper_inbuilt);
  
      gridview = (GridView) findViewById(R.id.gridview);
      final ImageAdapter IA = new ImageAdapter(this, img);
      gridview.setAdapter(IA);
  
      gridview.setOnItemClickListener(new OnItemClickListener() {
      public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) {
  try{
  
  
                   Uri y = Uri.parse("com.NM.quote_db/drawable/"+R.drawable.cloudy1);
                   //Intent intent = new Intent(); 
                   Intent intent = new Intent("com.android.camera.action.CROP");
                          intent.setDataAndType(y, "image/*");
                  // intent.setData(y);
                          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, PIC_CROP);
                          Toast.makeText(getApplicationContext(), "Activity found", Toast.LENGTH_SHORT).show();
                                         startActivityForResult(intent, 1);*/
                  }        
  
                  catch(ActivityNotFoundException e)
                  {
                      Toast.makeText(getApplicationContext(), "Activity not found", Toast.LENGTH_SHORT).show();
                  }
  
      });
  
  }
  
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   try
   {
  
  
   if (resultCode == RESULT_OK || resultCode == RESULT_CANCELED) {
           if(requestCode == PIC_CROP){
                  //get the returned data
  
  
                  Bundle extras = data.getExtras();
                  //get the cropped bitmap
                  Bitmap thePic = extras.getParcelable("data");
  
                  wpm = WallpaperManager.getInstance(getApplicationContext());
                  try {
                      wpm.setBitmap(thePic);
                      Toast.makeText(getApplicationContext(), "wallpaper set", Toast.LENGTH_SHORT).show();
  
                  } catch (IOException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
                      }
  
               else
                      Toast.makeText(getApplicationContext(), "Request code does not match", Toast.LENGTH_SHORT).show();
          }
          else
              Toast.makeText(getApplicationContext(), "result code does not match", Toast.LENGTH_SHORT).show();
          Toast.makeText(getApplicationContext(), "result code is"+ Integer.toString(resultCode), Toast.LENGTH_SHORT).show();
  
      }
   catch(Exception e)
   {
       Toast.makeText(getApplicationContext(), "outside start activity result method", Toast.LENGTH_SHORT).show();
   }
   }}
  </code></pre>
  
  <p><strong>Image Adapter Class</strong></p>
  
  <pre><code>public class ImageAdapter extends BaseAdapter {
      Context ImageGallaryContext;
      Integer[] ImgId;
      private Bitmap[] bitmap;
  
      public ImageAdapter(Context c, Integer[] ImgId) {
          ImageGallaryContext = c;
          this.ImgId = ImgId;
          bitmap = new Bitmap[getCount()];
      }
  
      @Override
      public int getCount() {
          // TODO Auto-generated method stub
          return ImgId.length;
      }
  
      @Override
      public Object getItem(int position) {
          // TODO Auto-generated method stub
          bitmap[position] = BitmapFactory.decodeResource(ImageGallaryContext.getResources(), ImgId[position]);
          return bitmap[position];
      }
  
      @Override
      public long getItemId(int position) {
          // TODO Auto-generated method stub
          return position;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          ImageView iView;
          if (convertView == null) {
              iView = new ImageView(ImageGallaryContext);
              iView.setLayoutParams(new GridView.LayoutParams(185, 185));
              iView.setScaleType(ImageView.ScaleType.CENTER_CROP);
              iView.setPadding(5, 5, 5, 5);
          } else {
              iView = (ImageView) convertView;
          }
          iView.setImageResource(ImgId[position]);
          return iView;
          /*
           * Intent i = new Intent(this, Wallpaper.class); startActivity(i);
           */
      }
  
  }
  </code></pre>