Skip to content

Commit

Permalink
Merge pull request #18 from viordash/image-formats
Browse files Browse the repository at this point in the history
support new Image formats
  • Loading branch information
viordash authored Sep 29, 2023
2 parents 1ea8536 + d08971b commit 6b0e30c
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion ShareClipbrd/Clipboard.Core/ClipboardData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static class Format {

public const string WaveAudio = "WaveAudio";

public const string PNG = "PNG";
public const string Dib = "DeviceIndependentBitmap";

public const string ImageBmp = "image/bmp";
Expand Down Expand Up @@ -418,7 +419,42 @@ public static class Format {
(stream) => {
if(OperatingSystem.IsWindows()) {
return stream switch {
MemoryStream memoryStream => memoryStream.ToArray(),
MemoryStream memoryStream => memoryStream,
_ => throw new ArgumentException(nameof(stream))
};
}
if(OperatingSystem.IsLinux()) {
return stream switch {
MemoryStream memoryStream => ImageConverter.FromDibToBmpFileData(memoryStream),
_ => throw new ArgumentException(nameof(stream))
};
}
throw new NotSupportedException($"OS: {Environment.OSVersion}");
},
() => {
if(OperatingSystem.IsWindows()) {
return Format.Dib;
}
if(OperatingSystem.IsLinux()) {
return Format.ImageBmp;
}
throw new NotSupportedException($"OS: {Environment.OSVersion}");
}
)},

{ Format.PNG, new Convert(
async (c, getDataFunc) => {
var data = await getDataFunc(Format.Dib);
if (data is MemoryStream castedValue) {c.Add(Format.Dib, castedValue); return true; }
if (data is byte[] bytes) {c.Add(Format.Dib, new MemoryStream(bytes)); return true; }
return false;
},
(stream) => {
if(OperatingSystem.IsWindows()) {
return stream switch {
MemoryStream memoryStream => memoryStream,
_ => throw new ArgumentException(nameof(stream))
};
}
Expand Down

0 comments on commit 6b0e30c

Please sign in to comment.