private void PerformCrop() { try { //call the standard crop action intent (the user device may not support it) Intent cropIntent = new Intent("com.android.camera.action.CROP"); //indicate image type and Uri cropIntent.SetDataAndType(fileUri, "image/*"); //set crop properties cropIntent.PutExtra("crop", "true"); //indicate aspect of desired crop cropIntent.PutExtra("aspectX", 1); cropIntent.PutExtra("aspectY", 1); //indicate output X and Y cropIntent.PutExtra("outputX", 256); cropIntent.PutExtra("outputY", 256); //retrieve data on return cropIntent.PutExtra("return-data", true); Android.Net.Uri tempURI = CameraGalleryClass.GetInstance(context).GetTempFile(); cropIntent.PutExtra(MediaStore.ExtraOutput, tempURI); //start the activity - we handle returning in onActivityResult activity.StartActivityForResult(cropIntent, PicCrop); } catch (ActivityNotFoundException anfe) { //display an error message showMessageObject.ShowMessage("Your_crop_action" + anfe); } catch (Java.Lang.Exception e) { showMessageObject.ShowMessage(e.ToString()); } }
private void GetImageFromGallery() { try { DecodeBitmap(PicFromGallery); if (!CameraGalleryClass.GetInstance(context).GetDeviceModelNumber().Contains("Nexus")) { PerformCrop(); } else { getImageBitmapAsync(newBitmap); } } catch (Java.Lang.Exception e) { PrintLogDetails.GetInstance().PrintErrorDetails("", "GetImageFromGallery", e.ToString()); } }
private void PreviewCapturedImage() { try { DecodeBitmap(CameraCaptureImageRequestCode); //rotateImageBy90Degree (); if (!CameraGalleryClass.GetInstance(context).GetDeviceModelNumber().Contains("Nexus")) { PerformCrop(); } else { getImageBitmapAsync(newBitmap); } } catch (Java.Lang.Exception e) { showMessageObject.ShowMessage(e.ToString()); } }
public void AlertCameraGallery() { AlertDialog alertDialog = new AlertDialog.Builder(context, AlertDialog.ThemeHoloLight).Create(); var dialougeView = activity.LayoutInflater.Inflate(Resource.Layout.custom_image_picker_layout, null); alertDialog.SetTitle("Complete action using"); alertDialog.SetView(dialougeView); TextView cameraTextView = dialougeView.FindViewById <TextView>(Resource.Id.camera_txt); TextView galleryTextView = dialougeView.FindViewById <TextView>(Resource.Id.gallery_txt); Button cancelBtn = dialougeView.FindViewById <Button>(Resource.Id.cancel); galleryTextView.Text = "Photo"; cameraTextView.Text = "Video"; if (!((Activity)context).IsFinishing) { //show dialog alertDialog.Show(); } // cancel the alert cancelBtn.Click += delegate { alertDialog.Dismiss(); alertDialog.Cancel(); }; // open the gallery for image galleryTextView.Click += delegate {// select the Photo if (CAMERA) { Intent intent = new Intent(MediaStore.ActionImageCapture); fileUri = CameraGalleryClass.GetInstance(context).GetTempFile(); intent.PutExtra(MediaStore.ExtraOutput, fileUri); // start the image capture Intent activity.StartActivityForResult(intent, CameraCaptureImageRequestCode); } else { Intent intent = new Intent(Intent.ActionPick, MediaStore.Images.Media.ExternalContentUri); activity.StartActivityForResult(intent, PicFromGallery); } alertDialog.Dismiss(); }; // open the gallery for video cameraTextView.Click += delegate { // select the VIDEO showMessageObject.ShowMessage(Resources.GetString(Resource.String.coming_soon)); //if (CAMERA) //{ // Random randomNumber = new Random(); // Java.IO.File videoFile = new Java.IO.File(Android.OS.Environment.ExternalStorageDirectory + "/com.Xamarin.Asem/Videos/"); // if (!videoFile.Exists()) // { // videoFile.Mkdirs(); // } // Intent intent = new Intent(MediaStore.ActionVideoCapture); // Android.Net.Uri videoFileUri = Android.Net.Uri.FromFile(new Java.IO.File(videoFile, "vid_" + randomNumber.Next() + ".mp4")); // intent.PutExtra(MediaStore.ExtraOutput, fileUri); // activity.StartActivityForResult(intent, CameraCaptureVideoRequestCode); //} //else //{ // Intent intent = new Intent(); // intent.SetType("video/*"); // intent.SetAction(Intent.ActionGetContent); // StartActivityForResult(Intent.CreateChooser(intent, "Select Video"), REQUEST_TAKE_GALLERY_VIDEO); //} alertDialog.Dismiss(); }; }