Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Fixes issue #795
Browse files Browse the repository at this point in the history
check the file extension when compressing the image when rotating or resizing the picked photo to use the correct compress format and avoid black background for transparent images
  • Loading branch information
DevEddy committed Jan 26, 2021
1 parent eede928 commit c6b8008
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Media.Plugin/Android/MediaImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,8 @@ public Task<bool> FixOrientationAndResizeAsync(string filePath, StoreCameraMedia

//if we need to rotate then go for it.
//then compresse it if needed
var photoType = System.IO.Path.GetExtension(filePath)?.ToLower();
var compressFormat = photoType == ".png" ? Bitmap.CompressFormat.Png : Bitmap.CompressFormat.Jpeg;
if (rotation != 0)
{
var matrix = new Matrix();
Expand All @@ -743,7 +745,7 @@ public Task<bool> FixOrientationAndResizeAsync(string filePath, StoreCameraMedia
//always need to compress to save back to disk
using (var stream = File.Open(filePath, FileMode.Create, FileAccess.ReadWrite))
{
rotatedImage.Compress(Bitmap.CompressFormat.Jpeg, mediaOptions.CompressionQuality, stream);
rotatedImage.Compress(compressFormat, mediaOptions.CompressionQuality, stream);
stream.Close();
}
rotatedImage.Recycle();
Expand All @@ -757,7 +759,7 @@ public Task<bool> FixOrientationAndResizeAsync(string filePath, StoreCameraMedia
//always need to compress to save back to disk
using (var stream = File.Open(filePath, FileMode.Create, FileAccess.ReadWrite))
{
originalImage.Compress(Bitmap.CompressFormat.Jpeg, mediaOptions.CompressionQuality, stream);
originalImage.Compress(compressFormat, mediaOptions.CompressionQuality, stream);
stream.Close();
}
}
Expand Down

0 comments on commit c6b8008

Please sign in to comment.