Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 36 additions & 8 deletions src/Plugin.Maui.Exif/Exif.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,43 @@ public async Task<bool> WriteToStreamAsync(Stream inputStream, Stream outputStre
{
try
{
// For streams, we need to copy the input to output and then modify the output
inputStream.Position = 0;
inputStream.CopyTo(outputStream);
outputStream.Position = 0;
// AndroidX ExifInterface.SaveAttributes() does not reliably persist changes
// when operating directly on streams. The workaround is to write to a
// temporary file, apply the EXIF modifications there, then copy the result
// to the output stream.
var tempFilePath = Path.Combine(Path.GetTempPath(), $"exif_temp_{Guid.NewGuid()}.jpg");

var exifInterface = new ExifInterface(outputStream);
WriteExifData(exifInterface, exifData);
exifInterface.SaveAttributes();
return true;
try
{
// Write input stream to temp file
inputStream.Position = 0;
using (var fileStream = File.Create(tempFilePath))
{
inputStream.CopyTo(fileStream);
}

// Apply EXIF data using file-based ExifInterface (reliable)
var exifInterface = new ExifInterface(tempFilePath);
WriteExifData(exifInterface, exifData);
exifInterface.SaveAttributes();

// Copy the modified file to the output stream
using (var resultStream = File.OpenRead(tempFilePath))
{
resultStream.CopyTo(outputStream);
}

outputStream.Position = 0;
return true;
}
finally
{
// Clean up temp file
if (File.Exists(tempFilePath))
{
File.Delete(tempFilePath);
}
}
}
catch (Exception)
{
Expand Down
Loading