Skip to content

Commit

Permalink
fixed: can't save HEIC due to error "Unsupported image format"
Browse files Browse the repository at this point in the history
  • Loading branch information
d2phap committed Jan 12, 2024
1 parent f08ed0d commit 59a243a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ public class IgMetadata
public string FileSizeFormated => BHelper.FormatSize(FileSize);


/// <summary>
/// Gets a value indicating whether the format can be written.
/// </summary>
public bool SupportsWriting { get; set; } = true;


// Image data
public int OriginalWidth { get; set; } = 0;
public int OriginalHeight { get; set; } = 0;
Expand Down
13 changes: 10 additions & 3 deletions Source/Components/ImageGlass.Base/Photoing/Codecs/PhotoCodec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ public static class PhotoCodec
meta.OriginalWidth = imgM.BaseWidth;
meta.OriginalHeight = imgM.BaseHeight;

meta.SupportsWriting = MagickFormatInfo.Create(imgM.Format).SupportsWriting;
meta.HasAlpha = imgC.Any(i => i.HasAlpha);
meta.ColorSpace = imgM.ColorSpace.ToString();

Expand Down Expand Up @@ -366,6 +365,15 @@ public static string GetThumbnailBase64(string filePath, int width, int height)
}


/// <summary>
/// Checks if the format can be written.
/// </summary>
public static bool CheckSupportFormatForSaving(string destFilePath)
{
return MagickFormatInfo.Create(destFilePath).SupportsWriting;
}


/// <summary>
/// Save as image file, use Magick.NET.
/// </summary>
Expand All @@ -381,8 +389,7 @@ public static async Task SaveAsync(string srcFileName, string destFilePath, Code

try
{
var metadata = LoadMetadata(srcFileName, readOptions);
if (!metadata.SupportsWriting)
if (!CheckSupportFormatForSaving(destFilePath))
{
throw new FileFormatException("IGE_001: Unsupported image format.");
}
Expand Down

0 comments on commit 59a243a

Please sign in to comment.