The basic use of Xamarin.ios camera and photo album

Source: Internet
Author: User

Summary of the contents of this article: 1. Call system camera and photo album Get photos

2. Set the selection or take a picture after the call system cropping function.

3. Set the system camera and album language as Chinese.


The first is to create a uiactionsheet with a photo album with a camera and a Cancel button, and open the camera and photo album in the button click event. Code:

		Bottom Selection window private uiactionsheet _actionsheet = null;
					Public Uiactionsheet Actionsheet {get {if (_actionsheet = null) {_actionsheet = new Uiactionsheet ();
					_actionsheet.addbutton ("album");
					_actionsheet.addbutton ("Camera");

					_actionsheet.addbutton ("cancellation");
					Set Cancel button Position _actionsheet.cancelbuttonindex = _actionsheet.buttoncount-1; _actionsheet.dismissed + = Async (sender, E) => {//Photo album if (e.buttonindex = 0) {//Set Cancel selection Fetch and End Select a method to return a picture _imagepicker.finishedpickingmedia + = this.

							Imagepicker_finishedpickermedia;
							You can crop _imagepicker.allowsediting = True when you select a photo; _imagepicker.canceled = this.

							imagepicker_cancelled;

							Set Image source for album _imagepicker.sourcetype = Uiimagepickercontrollersourcetype.photolibrary; Go to photo gallery await this.
						Presentviewcontrollerasync (This._imagepicker, true); //Camera else if (E.buttonindex = 1) {//Determine if there is hardware support if (Uiimagepickercontroller.issourcetypeavailable (Uiimagepickercontrollersourcetype.camera)) {IsCa

								Mera = true; Set deselect and end selection method to return a picture _imagepicker.finishedpickingmedia + = this.
								Imagepicker_finishedpickermedia;

								_imagepicker.sourcetype = Uiimagepickercontrollersourcetype.camera;
								Set the photo to crop _imagepicker.allowsediting = true; _imagepicker.canceled = this.

								imagepicker_cancelled; Open the camera await this.
							Presentviewcontrollerasync (This._imagepicker, true);
								else {Uialertview Alertview = new Uialertview ();
								Alertview.title = "Sorry, this device does not have camera function";
								Alertview.addbutton ("Know It");
							Alertview.show ();
				}
						}
					};
			return _actionsheet; }
		}

Here is the photo album and Camera callback method:

		<summary>///Albums deselect the method after the call///</summary>///<param name= "sender" >Sender.</param>/ <param name= "E" >E.</param> private async void Imagepicker_cancelled (object sender, EventArgs e) {is
			Camera = false;
		Await This._imagepicker.dismissviewcontrollerasync (true);
		///<summary>///The method invoked after the album selection///</summary>///<param name= "Sender" >Sender.</param> <param name= "E" >E.</param> private async void Imagepicker_finishedpickermedia (object sender, Uiimagepickermediapickedeventargs e) {//Get the selected image Editedimage is the edited photo originalimage is the original artwork uiimage pickerimage = e.Inf

			O[uiimagepickercontroller.editedimage] as UIImage;
				Show the selected image in Image view ...//If it is a camera save the picture to the album if (Iscamera) {pickerimage.savetophotosalbum (s, error) =>
			{if (null!= error) {}});

			} Iscamera = false; Exit Photo Gallery application await _imagepicker.dismissviewcontrollerasync (trUE); }

Such basic photography and photo albums have been realized, but also need to pay attention to the issue of permissions. Add the following permissions in the Info.plist file:


These two are camera and album permissions

Privacy-camera Usage Description String Description: App needs your album rights

Privacy-photo Library Usage Description string Application instructions:

The following is a language that is specified in Chinese

Localization native Development Region string








Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.