Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support new Image formats #18

Merged
merged 2 commits into from
Sep 29, 2023
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
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
Loading