Skip to content
Open
Show file tree
Hide file tree
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
37 changes: 37 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,41 @@ public async Task SetImageAsync(string context, string imageLocation)
await _proxy.SendStreamDeckEvent(args);
}

public async Task SetPngImageAsync(string context, Bitmap image)
{
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);
imgBytes = imgByteStream.ToArray();
}

var imgString = Convert.ToBase64String(imgBytes, Base64FormattingOptions.None);

await SetImageDataAsync(context, $"data:image/png;base64, {imgString}");
}

public async Task SetImageDataAsync(string context, string imageData)
{
Debug.WriteLine("Getting Image from image data");
_logger?.LogDebug("Getting Image from image data");

var args = new SetImageArgs
{
context = context,
payload = new SetImageArgs.Payload
{
TargetType = SetTitleArgs.TargetType.HardwareAndSoftware,
image = imageData
}
};

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