diff --git a/ffi/dotnet/Devolutions.IronRdp.ConnectExample/Devolutions.IronRdp.ConnectExample.csproj b/ffi/dotnet/Devolutions.IronRdp.ConnectExample/Devolutions.IronRdp.ConnectExample.csproj
index 166fc742..97974c7b 100644
--- a/ffi/dotnet/Devolutions.IronRdp.ConnectExample/Devolutions.IronRdp.ConnectExample.csproj
+++ b/ffi/dotnet/Devolutions.IronRdp.ConnectExample/Devolutions.IronRdp.ConnectExample.csproj
@@ -9,10 +9,14 @@
-
-
-
+
+
diff --git a/ffi/dotnet/Devolutions.IronRdp.ConnectExample/Program.cs b/ffi/dotnet/Devolutions.IronRdp.ConnectExample/Program.cs
index 619e4b0c..3be56f89 100644
--- a/ffi/dotnet/Devolutions.IronRdp.ConnectExample/Program.cs
+++ b/ffi/dotnet/Devolutions.IronRdp.ConnectExample/Program.cs
@@ -1,5 +1,5 @@
-using System.Drawing;
-using System.Drawing.Imaging;
+using SixLabors.ImageSharp;
+using SixLabors.ImageSharp.PixelFormats;
namespace Devolutions.IronRdp.ConnectExample
{
@@ -81,33 +81,27 @@ namespace Devolutions.IronRdp.ConnectExample
var bytes = new byte[data.GetSize()];
data.Fill(bytes);
- for (int i = 0; i < bytes.Length; i += 4)
+ using Image image = new Image(width, height);
+
+ // We’ll mutate this struct instead of creating a new one for performance reasons.
+ Rgba32 color = new Rgba32(0, 0, 0);
+
+ for (int col = 0; col < width; ++col)
{
- byte temp = bytes[i]; // Store the original Blue value
- bytes[i] = bytes[i + 2]; // Move Red to Blue's position
- bytes[i + 2] = temp; // Move original Blue to Red's position
- // Green (bytes[i+1]) and Alpha (bytes[i+3]) remain unchanged
+ for (int row = 0; row < height; ++row)
+ {
+ var idx = (row * width + col) * 4;
+
+ color.R = bytes[idx];
+ color.G = bytes[idx + 1];
+ color.B = bytes[idx + 2];
+
+ image[col, row] = color;
+ }
}
-#if WINDOWS // Bitmap is only available on Windows
- using (var bmp = new Bitmap(width, height))
- {
- // Lock the bits of the bitmap.
- var bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
- ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
-
- // Get the address of the first line.
- IntPtr ptr = bmpData.Scan0;
- // Copy the RGBA values back to the bitmap
- System.Runtime.InteropServices.Marshal.Copy(bytes, 0, ptr, bytes.Length);
- // Unlock the bits.
- bmp.UnlockBits(bmpData);
-
- // Save the bitmap to the specified output path
- bmp.Save("./output.bmp", ImageFormat.Bmp);
- }
-#endif
-
+ // Save the image as bitmap.
+ image.Save("./output.bmp");
}
static Dictionary? ParseArguments(string[] args)
diff --git a/ffi/dotnet/Devolutions.IronRdp/src/Connection.cs b/ffi/dotnet/Devolutions.IronRdp/src/Connection.cs
index d1cd0c9d..38d2f8f7 100644
--- a/ffi/dotnet/Devolutions.IronRdp/src/Connection.cs
+++ b/ffi/dotnet/Devolutions.IronRdp/src/Connection.cs
@@ -199,9 +199,12 @@ public class Connection
{
IPAddress ipAddress;
- try {
+ try
+ {
ipAddress = IPAddress.Parse(servername);
- } catch (FormatException) {
+ }
+ catch (FormatException)
+ {
IPHostEntry ipHostInfo = await Dns.GetHostEntryAsync(servername);
ipAddress = ipHostInfo.AddressList[0];
}