mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 19:27:56 +01:00
This commit is contained in:
committed by
GitHub
parent
b6affde530
commit
d39c4121a9
@@ -187,6 +187,31 @@ namespace ImageResizer.Extensions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Detect whether the metadata object is valid and can be copied successfully
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// ImageMetadata.Clone() causes an exception if there is something wrong with the metadata object.
|
||||||
|
/// Operation is rather expensive.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="metadata">Metadata object to be checked</param>
|
||||||
|
/// <returns>true if valid, false if invalid</returns>
|
||||||
|
public static bool IsMetadataObjectValid(this BitmapMetadata metadata)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_ = metadata.Clone();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#pragma warning disable CA1031 // Do not catch general exception types
|
||||||
|
catch (Exception)
|
||||||
|
#pragma warning restore CA1031 // Do not catch general exception types
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Prints all metadata to debug console
|
/// Prints all metadata to debug console
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -104,7 +104,15 @@ namespace ImageResizer.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata = newMetadata;
|
if (newMetadata.IsMetadataObjectValid())
|
||||||
|
{
|
||||||
|
metadata = newMetadata;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Seems like we build an invalid metadata object. ImageResizer will fail when trying to write the image to disk. We discard all metadata to be able to save the image.
|
||||||
|
metadata = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (ArgumentException ex)
|
catch (ArgumentException ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user