Take picture in UWP with Plugin.Media - image

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.

Related

Application get crash in Ipad when camera is called second time in xamarin

I am using a camera on button click, but when user press the button second time the application get crashed. This is only happening on Ipad, its working smoothly on Iphone and android phones. I am using below code to initiate the camera.
if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
await App.Current.MainPage.DisplayAlert("No Camera", ":( No camera avaialble.", "OK");
return;
}
var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
{
PhotoSize = Plugin.Media.Abstractions.PhotoSize.Small,
DefaultCamera = Plugin.Media.Abstractions.CameraDevice.Rear,
Directory = "Sample",
Name = "test.jpg"
});
if (file == null)
return;
var lStream = file.GetStream();

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

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

Xamarin forms CrossMedia.Current asking permission

I am developing a xamarin forms application which access device camera and gallery to take pictures. I am using the following code
CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
{
SaveToAlbum = true,
Name = string.Format(TDJGolfConstants.ProfileImageName, Guid.NewGuid()),
//AllowCropping = true,
//CompressionQuality = 60,
PhotoSize= PhotoSize.Medium,
But it is not asking the user for permission , and directly opens the camera and gallery. Is there anything to add for asking permisision?
I use CrossPermissions from the PermissionsPlugin for this
var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera);
if (status != PermissionStatus.Granted)
{
if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Camera))
{
await UserNotificationService.Current.Show("Camera required", "justification");
}
var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Camera);

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.

Unable to rotate image in windows store app

I'm attempting to take a photo with my device camera, but images taken with the device held in "portrait" mode come out sideways. I'd like to rotate them before saving them, but the solution that I keep coming across isn't working for me.
Windows.Storage.Streams.InMemoryRandomAccessStream stream = new Windows.Storage.Streams.InMemoryRandomAccessStream();
imagePreview.Source = null;
await stream.WriteAsync(currentImage.AsBuffer());
stream.Seek(0);
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
BitmapEncoder encoder = await BitmapEncoder.CreateForTranscodingAsync(stream, decoder);
encoder.BitmapTransform.Rotation = BitmapRotation.Clockwise90Degrees;
encoder.IsThumbnailGenerated = false;
await encoder.FlushAsync();
//save the image
StorageFolder folder = KnownFolders.SavedPictures;
StorageFile capturefile = await folder.CreateFileAsync("photo_" + DateTime.Now.Ticks.ToString() + ".bmp", CreationCollisionOption.ReplaceExisting);
string captureFileName = capturefile.Name;
//store stream in file
using (var fileStream = await capturefile.OpenStreamForWriteAsync())
{
try
{
//because of using statement stream will be closed automatically after copying finished
await Windows.Storage.Streams.RandomAccessStream.CopyAsync(stream, fileStream.AsOutputStream());
}
catch
{
}
}
this produces the original image with no rotation applied to it. I've looked at a lot of samples, and can't figure out what I'm doing wrong.

Resources