Skip to content

Commit 6f1f7cb

Browse files
Merge pull request #394 from shotr-io/master
Implement NativeImage support, fixes #14
2 parents aec0da6 + c9f0c43 commit 6f1f7cb

File tree

17 files changed

+915
-110
lines changed

17 files changed

+915
-110
lines changed

ElectronNET.API/Clipboard.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,40 @@ public void Write(Data data, string type = "")
237237
BridgeConnector.Socket.Emit("clipboard-write", JObject.FromObject(data, _jsonSerializer), type);
238238
}
239239

240+
/// <summary>
241+
/// Reads an image from the clipboard.
242+
/// </summary>
243+
/// <param name="type"></param>
244+
/// <returns></returns>
245+
public Task<NativeImage> ReadImageAsync(string type = "")
246+
{
247+
var taskCompletionSource = new TaskCompletionSource<NativeImage>();
248+
249+
BridgeConnector.Socket.On("clipboard-readImage-Completed", (image) =>
250+
{
251+
BridgeConnector.Socket.Off("clipboard-readImage-Completed");
252+
253+
var nativeImage = ((JObject)image).ToObject<NativeImage>();
254+
255+
taskCompletionSource.SetResult(nativeImage);
256+
257+
});
258+
259+
BridgeConnector.Socket.Emit("clipboard-readImage", type);
260+
261+
return taskCompletionSource.Task;
262+
}
263+
264+
/// <summary>
265+
/// Writes an image to the clipboard.
266+
/// </summary>
267+
/// <param name="image"></param>
268+
/// <param name="type"></param>
269+
public void WriteImage(NativeImage image, string type = "")
270+
{
271+
BridgeConnector.Socket.Emit("clipboard-writeImage", JsonConvert.SerializeObject(image), type);
272+
}
273+
240274
private JsonSerializer _jsonSerializer = new JsonSerializer()
241275
{
242276
ContractResolver = new CamelCasePropertyNamesContractResolver(),

ElectronNET.API/ElectronNET.API.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ This package contains the API to access the "native" electron API.</Description>
4141
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
4242
</PackageReference>
4343
<PackageReference Include="SocketIoClientDotNet" Version="1.0.5" />
44+
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
4445
</ItemGroup>
4546

4647
</Project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace ElectronNET.API.Entities
2+
{
3+
/// <summary>
4+
///
5+
/// </summary>
6+
public class AddRepresentationOptions
7+
{
8+
/// <summary>
9+
/// Gets or sets the width
10+
/// </summary>
11+
public int? Width { get; set; }
12+
13+
/// <summary>
14+
/// Gets or sets the height
15+
/// </summary>
16+
public int? Height { get; set; }
17+
18+
/// <summary>
19+
/// Gets or sets the scalefactor
20+
/// </summary>
21+
public float ScaleFactor { get; set; } = 1.0f;
22+
23+
/// <summary>
24+
/// Gets or sets the buffer
25+
/// </summary>
26+
public byte[] Buffer { get; set; }
27+
28+
/// <summary>
29+
/// Gets or sets the dataURL
30+
/// </summary>
31+
public string DataUrl { get; set; }
32+
}
33+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace ElectronNET.API.Entities
2+
{
3+
/// <summary>
4+
///
5+
/// </summary>
6+
public class BitmapOptions
7+
{
8+
/// <summary>
9+
/// Gets or sets the scale factor
10+
/// </summary>
11+
public float ScaleFactor { get; set; } = 1.0f;
12+
}
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace ElectronNET.API.Entities
2+
{
3+
/// <summary>
4+
///
5+
/// </summary>
6+
public class CreateFromBitmapOptions
7+
{
8+
/// <summary>
9+
/// Gets or sets the width
10+
/// </summary>
11+
public int? Width { get; set; }
12+
13+
/// <summary>
14+
/// Gets or sets the height
15+
/// </summary>
16+
public int? Height { get; set; }
17+
18+
/// <summary>
19+
/// Gets or sets the scalefactor
20+
/// </summary>
21+
public float ScaleFactor { get; set; } = 1.0f;
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace ElectronNET.API.Entities
2+
{
3+
/// <summary>
4+
///
5+
/// </summary>
6+
public class CreateFromBufferOptions
7+
{
8+
/// <summary>
9+
/// Gets or sets the width
10+
/// </summary>
11+
public int? Width { get; set; }
12+
13+
/// <summary>
14+
/// Gets or sets the height
15+
/// </summary>
16+
public int? Height { get; set; }
17+
18+
/// <summary>
19+
/// Gets or sets the scalefactor
20+
/// </summary>
21+
public float ScaleFactor { get; set; } = 1.0f;
22+
}
23+
}

0 commit comments

Comments
 (0)