[mono-android] taking a pic

efontana eric at fontanas.net
Wed Jan 25 19:03:00 UTC 2012


  void cropPicture(Intent data)
    {
      Intent intent = new Intent("com.android.camera.action.CROP");
      intent.SetType("image/*");
      List<Android.Content.PM.ResolveInfo> list =
PackageManager.QueryIntentActivities(intent, 0).ToList();
      List<CropOption> cropOptions = new List<CropOption>();

      if (list.Count == 0)
      {
        Toast.MakeText(this, "Cannot find image crop Application",
ToastLength.Short).Show();
        return;
      }

      if (list.Count == 1)
      {
        intent.SetData(_photoURI);
        intent.PutExtra("outputX", 156);
        intent.PutExtra("outputY", 156);
        intent.PutExtra("aspectX", 1);
        intent.PutExtra("aspectY", 1);
        intent.PutExtra("scale", true);
        intent.PutExtra("return-data", true);
        Intent i = new Intent(intent);
        Android.Content.PM.ResolveInfo res = list[0];
        i.SetComponent(new ComponentName(res.ActivityInfo.PackageName,
res.ActivityInfo.Name));
        StartActivityForResult(i, CROP_FROM_CAMERA);
      }
      else
      {
        foreach (Android.Content.PM.ResolveInfo res in list)
        {
          CropOption co = new CropOption();

          co.title =
PackageManager.GetApplicationLabel(res.ActivityInfo.ApplicationInfo);
          co.icon =
PackageManager.GetApplicationIcon(res.ActivityInfo.ApplicationInfo);
          co.appIntent = new Intent(intent);
          co.appIntent.SetComponent(new
ComponentName(res.ActivityInfo.PackageName, res.ActivityInfo.Name));
          cropOptions.Add(co);
        }

        CropOptionAdapter adapter = new CropOptionAdapter(this,
cropOptions);
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.SetTitle("Choose Crop App");
        builder.SetAdapter(adapter, new CropListener(this, cropOptions));
        AlertDialog alert = builder.Create();
        alert.Show();
      }
    }


-----
iPhone and Android Developer

www.ericfontana.com 

--
View this message in context: http://mono-for-android.1047100.n5.nabble.com/taking-a-pic-tp5158900p5431028.html
Sent from the Mono for Android mailing list archive at Nabble.com.


More information about the Monodroid mailing list