Cross-Platform Support for Saving Images in JPG Format in .NET MAUI #31657
Replies: 2 comments
-
Talking to CoPilot AI, you could implement your reusable cross‑platform image saver service. Each platform would threat .jpg/.jpeg file extension properly. Learned from CoPilot AI, it's not an MAUI bug, it's an OS specific working you can cover making. I copied your content to CoPilot AI and got reusable cross‑platform image saver service. |
Beta Was this translation helpful? Give feedback.
-
I just did recent project (just Android/iOS only) where we were pulling images from the Camera and downsizing/compressing them to target max file size and saving out to jpg for submission to backend API. Not sure if this helps - but this is what I discovered :
It sounds weird the file extension for jpeg is making so much difference here - typically the other tooling is primarily looking at the header of the output file - surprised it doesn't work with either extension as both are commonly used. We did use '.jpg' instead of '.jpeg' but I'm not convinced this would cause the issues. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am developing an image-saving feature in a .NET MAUI application and am seeking guidance on ensuring consistent, cross-platform behavior.
The goal is to allow users to save images in the following formats:
.png
).jpeg
).bmp
).jpeg
for JPEG-encoded images)While PNG, JPEG, and BMP are mostly supported across platforms, adding support for
.jpg
extension has revealed inconsistent behavior across platforms.Current Implementation Status:
Windows:
.png
,.jpeg
,.bmp
, and.jpg
by providing the format as a string..jpg
and.jpeg
files have identical sizes (e.g., both 300 KB). However, unclear whether this behavior is correct.Android:
Bitmap.CompressFormat.JPEG
, Android'sMediaStore
automatically assigns a.jpg
extension based on theimage/jpeg
MIME type, regardless of whether.jpeg
was specified in the filename..iOS/MacCatalyst:
UIImage.AsJPEG()
andUIImage.AsPNG()
work reliably for saving files with.jpeg
and.png
extensions..jpg
extension results in:.png
extension or not recognized)..jpeg
and.png
extensions seem to work reliably.Questions:
.jpg
extension on all platforms, especially iOS?UIImage
or the underlying OS, where it strictly prefers the.jpeg
extension?MediaStore
's default behavior to enforce a user-specified extension, or should we align with the platform's convention and always use.jpg
?.jpg
be treated as an alias for .jpeg within the application's logic, with platform-specific code to handle the final file extension, or is there a more unified approach?Any insights, workarounds, or roadmap updates would be greatly appreciated. Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions