How to set Longitude And Latitude to picture using xamarin forms? - xamarin

I am new in Xamarin Forms and I got a task. I want to create one camera application which takes photos with details of longitude and latitude. I have created a camera app, but I am stuck on one question: how do I set longitude and latitude properties of taken pic?
Here is my code to take a photo, now I have to set details longitude and latitude:
private MediaFile _mediaFile;
private async void TakePhoto_Clicked(object sender, EventArgs e)
{
await CrossMedia.Current.Initialize();
if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
await DisplayAlert("No Camera", ":( No camera available.", "OK");
return;
}
_mediaFile = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
{
Directory = "Sample",
Name = "myImage.jpg",
SaveToAlbum = true
});
if (_mediaFile == null)
return;
LocalPathLabel.Text = _mediaFile.Path;
FileImage.Source = ImageSource.FromStream(() =>
{
return _mediaFile.GetStream();
});
}
Can you please help me with my task?

You can refer below link for saving properties of Image for Android. Same way there has to be something for iOS.
https://forums.xamarin.com/discussion/73547/how-to-add-properties-location-to-image

Related

How to rotate an image by 90 degrees on every button click in Xamarin forms application?

I am using the Plugin. Media to pick a photo from my gallery. I would like to provide the users an option to rotate the image when they click on it.
When I use the rotate property, I am able to rotate the image once. But, I would like to rotate it by 90 degrees every time the user clicks on a button.
if (!CrossMedia.Current.IsPickPhotoSupported)
{
await DisplayAlert("Photos Not Supported", "Permission not granted
to photos", "OK");
return;
}
var file = Plugin.Media.CrossMedia.Current.PickPhotoAsync(new
Plugin.Media.Abstractions.PickMediaOptions
{
PhotoSize = Plugin.Media.Abstractions.PhotoSize.Small
});
if (file == null)
return;
imageProfile.Source = ImageSource.FromStream(() =>
{
var stream = file.Result.GetStream();
file.Result.Dispose();
return stream;
});
public void rotateButton_Clicked(object sender, Event args e) {
imageProfile.RotateX(90);
// This event allows me to rotate the image only once.
}
int angle = 0;
public void rotateButton_Clicked(object sender, Event args e) {
angle += 90;
imageProfile.RotateX(angle);
}

Xamarin Forms Media Plugin - Take photo return to screen pops to root

I'm experiencing the issue here on an iOS phone.
https://github.com/jamesmontemagno/MediaPlugin/issues/433?_pjax=%23js-repo-pjax-container
here's the code that navigates to the photo page. You can see all the different things I tried
private async void addPhotosClickedAsync(object sender, EventArgs args)
{
// await ((RootPage)Application.Current.MainPage).Detail.Navigation.PushAsync(new TakePhoto(_workOrderId));
// await ((RootPage)App.Current.MainPage).Detail.Navigation.PushModalAsync(new TakePhoto(_workOrderId));
//Device.BeginInvokeOnMainThread(async () =>
//{
// await Navigation.PushAsync(new TakePhoto(_workOrderId));
//});
await ((RootPage)App.Current.MainPage).Detail.Navigation.PushAsync(new TakePhoto(_workOrderId));
}
On the camera page, there is a camera button icon that invokes the media plugin to take a picture. When the picture UI returns, it sets an image source to the photo just taken. The UI returns for a moment, then all of a sudden the app pops back to root
private async Task OnCameraTapped(object sender, EventArgs args)
{
CameraHelper cameraHelper = new CameraHelper();
try
{
ImgBytes = await cameraHelper.TakePicture();
PhotoImage.Source = ImageSource.FromStream(() =>
{
return new MemoryStream(ImgBytes);
});
}
catch (Exception ex)
{
if (ex.Message == "No camera available")
{
await DisplayAlert("Error", "No camera available", "Ok");
}
else
{
await DisplayAlert("Error", "Unable to take picture.", "Ok");
}
}
}
Is there some sort of work around for this?

Take picture in UWP with Plugin.Media

In a xaml xamarin project pcl (UWP) I can take a photo, however when the screen is opened to accept the image, it appears weakly in the background and the crop grid is summarized in the upper right corner.
All was well until one of the last updates.
Below I send the images of what happens.
My Windows version is 1703 OS Build 15063.540
My Windows Camera Version is 1017.727.20.0
How I solve this.
Thank you
I have tried to reproduce the issue with the following code. However, I could not reproduce. And The Gridlines that you mentioned is scale that to crop the photo. If you have set the selection, and the content out of selection will be weakly. It is by design.
takePhoto.Clicked += async (sender, args) =>
{
if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
await DisplayAlert("No Camera", ":( No camera avaialble.", "OK");
return;
}
var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
{
PhotoSize = Plugin.Media.Abstractions.PhotoSize.Full,
Directory = "Sample",
Name = "test.jpg"
});
if (file == null)
return;
await DisplayAlert("File Location", file.Path, "OK");
image.Source = ImageSource.FromStream(() =>
{
var stream = file.GetStream();
file.Dispose();
return stream;
});
};
If the issue is not caused by the inappropriate selection that above mentioned, you could check the camera physical device.

Xamarin.forms i want to upload image on same page

i am uploading my image by using plugins.media but the problem is it redirect to another photoimage page and upload it there.
var profiletap = new TapGestureRecognizer();
profiletap.Tapped += async (s, e) =>
{
var file = await CrossMedia.Current.PickPhotoAsync();
if (file == null)
return;
await DisplayAlert("File Location", file.Path, "OK");
ImageSource im = ImageSource.FromStream(() =>
{
var stream = file.GetStream();
file.Dispose();
return stream;
});
await Navigation.PushModalAsync(new PhotoPage(im));
};
profile.GestureRecognizers.Add(profiletap);
ant here is photopage content
public class PhotoPage : demopage
{
public PhotoPage(ImageSource img)
{
Content = new Image
{
VerticalOptions =LayoutOptions.Start,
HorizontalOptions = LayoutOptions.Start,
Source =img
};
}
}
Instead of doing
await Navigation.PushModalAsync(new PhotoPage(im));
you can do something like
var img = new Image
{
Source =im
};
then add the new img control to the same container as where the "profile" control has already been added (probably some Stacklayout or Grid or some other layout control like that)
Be aware that you are struggling with the most basic concept of building out your app UI, which is a strong indicator you should read some getting started tutorials for xamarin.forms and really understand how the UI is built.

Getting stream from file absolute path

This may sound very simple but I've lost a lot of time looking for answer
In my Windows phone 8 app I use the PhotoChooserTask to let the user choose the photo, and i get the path of the photo by using
string FileName = e.OriginalFileName;
where e is the PhotoResult argument of the Task. , let's say: FileName=
"C:\Data\SharedData\Comms\Unistore\data\18\k\2000000a00000018700b.dat" (selected from the cloud) or
"D:\Pictures\Camera Roll\WP_20140110_10_40_42_1_Smart.jpg" (from camera roll)
I want to save that string path and open it up and show the image again when the users reopen the app. But I cannot find a method to convert those string into Image data (BitmapImage or Stream)
Any idea?
private void PhotoChooserTaskCompleted(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
var image = new BitmapImage();
image.SetSource(e.ChosenPhoto);
SaveImageAsync(image);
}
}
public async void SaveImageAsync(BitmapImage image)
{
await Task.Run(SaveImage(image));
}
public async Task SaveImage(BitmapImage image)
{
IStorageFolder folder = await ApplicationData.Current.LocalFolder
.CreateFolderAsync("Images", CreationCollisionOption.OpenIfExists);
IStorageFile file = await folder.CreateFileAsync(
imageFileName, CreationCollisionOption.ReplaceExisting);
using (Stream stream = await file.OpenStreamForWriteAsync())
{
var wrBitmap = new WriteableBitmap(image);
wrBitmap.SaveJpeg(stream, image.PixelWidth, image.PixelHeight, 100, 100);
}
}
At Windows Phone 8.1 you can try "StorageFolder.GetFolderFromPathAsync" static method (if this API is available at your app flavor) and then get a stream for a necessary file from that folder.

Resources