mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 17:56:44 +02:00
[Image Resizer] Add option to remove metadata (#14176)
* Implements option to remove metadata (see #1928) * Add unit test * renamed settings switch, update ui text * Fix exception type, add justification for swallowing exception * Add unit test to check handling if no metadata is there in targetfile * Reordered the checkboxes as suggested by @htcfreek * Reduced size of test image
This commit is contained in:
committed by
GitHub
parent
9d9df949ef
commit
9ca32aa3ea
@@ -0,0 +1,55 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace ImageResizer.Extensions
|
||||
{
|
||||
internal static class BitmapMetadataExtension
|
||||
{
|
||||
public static void CopyMetadataPropertyTo(this BitmapMetadata source, BitmapMetadata target, string query)
|
||||
{
|
||||
if (source == null || target == null || string.IsNullOrWhiteSpace(query))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var value = source.GetQuerySafe(query);
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
target.SetQuery(query, value);
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
// InvalidOperationException is thrown if metadata object is in readonly state.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static object GetQuerySafe(this BitmapMetadata metadata, string query)
|
||||
{
|
||||
if (metadata == null || string.IsNullOrWhiteSpace(query))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return metadata.GetQuery(query);
|
||||
}
|
||||
catch (NotSupportedException)
|
||||
{
|
||||
// NotSupportedException is throw if the metadata entry is not preset on the target image (e.g. Orientation not set).
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user