question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AllowCropping rotating the saved picture 90 degrees clockwise

See original GitHub issue

Bug Information

Version Number of Plugin: 3.0.1 Device Tested On: iPhone 5, iPhone 7, Samsung Note4 Simulator Tested On: None Version of VS: 7.0.1 build 24 (for mac) Version of Xamarin: Versions of other things you are using:

Steps to reproduce the Behavior

  • add AllowCropping = true to StoreCameraMediaOptions
  • Take Photo in portrait orientation (bottom of photo is at iPhone button)
  • Save Photo

Expected Behavior

  • Photo appears on page same as taken (bottom of photo is at iPhone button)

Actual Behavior

  • Photo appears on page rotated 90 degrees clockwise (right side of photo is at iPhone button)

Code snippet

		public async void TakePhoto(object sender, EventArgs args)
		{
		    
            // Check to see if the camera is avialble and taking a photo is supported
		    if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
		    {

				await DisplayAlert("No Camera", ":( No camera available.", "OK");
		        return;
		    }

            // Take a photo.
            // Currently, save the file in a sample directory with the name test.jpg
			var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
			{
				
                // RESET PHOTO SIZE
				// By default the photo that is taken/picked is the maxiumum size and quality available. 
                // For most applications this is not needed and can be Resized. 
                // This can be accomplished by adjusting the PhotoSize property on the options. 
                // The easiest is to adjust it to Small, Medium, or Large, which is 25%, 50%, or 75% or the original.

				// Photo Size options examples

				PhotoSize = PhotoSize.Medium,

				//PhotoSize = PhotoSize.Custom,
                //CustomPhotoSize = 90, // Resize to 90% of original

                // PHOTO QUALITY
				// Set the CompressionQuality, which is a value from 0 the most compressed all the way to 100, which is no compression.
                // A good setting from testing is around 92
                CompressionQuality = 92,

                // SAVING PHOTO TO CAMERA ROLL
				// You can now save a photo or video to the camera roll/gallery.
				// When creating the StoreCameraMediaOptions or StoreVideoMediaOptions simply set SaveToAlbum to true.
				// When your user takes a photo it will still store temporary data, but also if needed make a copy to the public gallery (based on platform).
				// In the MediaFile you will now see a AlbumPath that you can query as well.
				// This will restult in 2 photos being saved for the photo.
                // One in your private folder and one in a public directory that is shown. The value will be returned at AlbumPath.
                // Android: When you set SaveToAlbum this will make it so your photos are public in the Pictures/YourDirectory or Movies/YourDirectory.
                // This is the only way Android can detect the photos.
                SaveToAlbum = true,

				// ALLOW CROPPING
                // iOS has crop controls built into the the camera control when taking a photo.
                // On iOS the default is false.
                // You can adjust the AllowCropping property when taking a photo to allow your user to crop.
                AllowCropping = true,

                // DEFAULT CAMERA
                // By default when you take a photo or video the default system camera will be selected.
                // Simply set the DefaultCamera on StoreCameraMediaOptions.
                // This option does not guarantee that the actual camera will be selected because each platform is different.
                // It seems to work extremely well on iOS,
                // but not so much on Android.Your mileage may vary.
                //DefaultCamera = CameraDevice.Front,

                // Where should we save our private copy of the photo
				Directory = "toms_camera_test_photos",

                // What should we name the photo
                // Might be a good idea to add a time stamp on here
				Name = "testPhoto" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg",

			});

			if (file == null)
				return;

			//Get the public album path
			var aPpath = file.AlbumPath;
			Debug.WriteLine("This is the file.AlbumPath " + aPpath);

			//Get private path
			var path = file.Path;
            Debug.WriteLine("This is the file.Path " + path);

            // Display an alert showing where the file was saved
			await DisplayAlert("File Location private path", path, "OK");

            // Update the Source for the image tag on the Xaml page with where we just saved the file
			image.Source = ImageSource.FromStream(() =>
			{
				var stream = file.GetStream();
				file.Dispose();
				return stream;
			});

			//or:
			//image.Source = ImageSource.FromFile(file.Path);
			//image.Dispose();
		}

Screenshotst

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jamesmontemagnocommented, Aug 31, 2017

@todorgrigorov this would be in all versions as I don’t manipulate the photo and apple is rotating it.

0reactions
jamesmontemagnocommented, Aug 31, 2017

Closing and putting this into a feature as rotating on iOS was never implemented like this.

See: https://github.com/jamesmontemagno/MediaPlugin/issues/334

Read more comments on GitHub >

github_iconTop Results From Across the Web

Edit, crop, or rotate pictures in OneNote for Windows 10
Click Rotate Left 90° to rotate the selected picture by 90 degrees counterclockwise. Click Flip Horizontal to flip the selected picture horizontally. Click...
Read more >
Xamarin Forms: Camera picture is left rotated when comes ...
It seems this is a known issue when you set AllowCropping to true, ... data you will find the edited image has been...
Read more >
How to rotate an image in Photoshop
With your image open in Photoshop, go to Image > Image Rotation. 2. Select from the image rotation options — 90 degrees clockwise,...
Read more >
How to Rotate and Save Images in Paint
Once you have the image open in Paint, you can rotate it in four ways: 90 degrees clockwise, 90 degrees counterclockwise, 180 degrees,...
Read more >
Flip or rotate pictures
Select either Rotate the image 90 degrees to the left or Rotate the image 90 degrees to the right. If you want to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found