Press "Enter" to skip to content

Xamarin.Forms Taking Picture

Hello, when i was develop an application, i was need the take a picture and pick the picture. I researched about the taking and picking picture and i find the Xam.Plugin.Media plugin which created by the James Montemagno. For the use that plugin, we need to make some arranges.

Firstly, after the creating project we need the add the Xam.Plugin.Media. Later inside of the Android platform and AndroidManifest, we need to add the below codes between the application tags. The Application ID in the code is your package name so change it.

Our job is done inside of the AndroidManifest. Now we should go Resources and create a folder which name is xml. In this folder, I create the file which name is file_paths.xml and wrote these below codes;

After that, go to Main Activity and initialize the plugin.

Plugin will work. So now we need the make the take picture, video and pick picture and video. Before that process, I made a simple design inside of the MainPage.xaml. I added a picture and 4 buttons.

I wrote the event for the each buttons. I started with the taking picture button. Firstly, I am controlling the situation of the camera. If the condition will be success, Camera will be open with the TakePhotoAsync() event. I give the properties of the image. For the showing image in the MainPage.xaml, I return a stream with the ImageSource.FromStream. So our image will be appear.

For the picking picture from the gallery, I control the supporting of the phone. If it is successfull, I pick the image with PickPhotoAsync event. For the showing image in the MainPage.xaml, again i use ImageSource.FromStream and we get the stream with GetStream function and we returned as an image.

Taking video and picking video process same as taking picture and picking picture so i will directly wrote the codes below.

Here is the output of the application;

You can ask your questions via e-mail or comments.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *