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

add bitmap support #171

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from
29 changes: 29 additions & 0 deletions src/StreamDeckLib/ConnectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.Net.WebSockets;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -260,6 +262,33 @@ public async Task SetImageAsync(string context, string imageLocation)
await _proxy.SendStreamDeckEvent(args);
}

public async Task SetPngImageAsync(string context, Bitmap image)
BenjaminAbt marked this conversation as resolved.
Show resolved Hide resolved
{
Debug.WriteLine("Getting Image from Bitmap");
_logger?.LogDebug("Getting Image from Bitmap");

byte[] imgBytes;
using (var imgByteStream = new MemoryStream())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
image.Save(imgByteStream, ImageFormat.Png);// force use png
imgBytes = imgByteStream.ToArray();
}
var imgString = Convert.ToBase64String(imgBytes, Base64FormattingOptions.None);

var args = new SetImageArgs
{
context = context,
payload = new SetImageArgs.Payload
{
TargetType = SetTitleArgs.TargetType.HardwareAndSoftware,
image = $"data:image/png;base64, {imgString}"
}
};

await _proxy.SendStreamDeckEvent(args);
}


public async Task ShowAlertAsync(string context)
{
var args = new ShowAlertArgs()
Expand Down
1 change: 1 addition & 0 deletions src/StreamDeckLib/StreamDeckLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.1.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Drawing.Common" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down