();
+ foreach (var item in dict)
+ {
+ var bytes = Convert.FromBase64String(item.Value);
+ newDictionary.Add(item.Key, Image.FromStream(new MemoryStream(bytes)));
+ }
+ return new NativeImage(newDictionary);
+ }
+
+ public override bool CanConvert(Type objectType) => objectType == typeof(NativeImage);
+ }
+}
diff --git a/ElectronNET.API/Entities/ResizeOptions.cs b/ElectronNET.API/Entities/ResizeOptions.cs
new file mode 100644
index 00000000..1490ccdb
--- /dev/null
+++ b/ElectronNET.API/Entities/ResizeOptions.cs
@@ -0,0 +1,23 @@
+namespace ElectronNET.API.Entities
+{
+ ///
+ ///
+ ///
+ public class ResizeOptions
+ {
+ ///
+ /// Gets or sets the width
+ ///
+ public int? Width { get; set; }
+
+ ///
+ /// Gets or sets the height
+ ///
+ public int? Height { get; set; }
+
+ ///
+ /// good, better, or best. Default is "best";
+ ///
+ public string Quality { get; set; } = "best";
+ }
+}
diff --git a/ElectronNET.API/Entities/ToBitmapOptions.cs b/ElectronNET.API/Entities/ToBitmapOptions.cs
new file mode 100644
index 00000000..1a08c3bf
--- /dev/null
+++ b/ElectronNET.API/Entities/ToBitmapOptions.cs
@@ -0,0 +1,13 @@
+namespace ElectronNET.API.Entities
+{
+ ///
+ ///
+ ///
+ public class ToBitmapOptions
+ {
+ ///
+ /// Gets or sets the scalefactor
+ ///
+ public float ScaleFactor { get; set; } = 1.0f;
+ }
+}
diff --git a/ElectronNET.API/Entities/ToDataUrlOptions.cs b/ElectronNET.API/Entities/ToDataUrlOptions.cs
new file mode 100644
index 00000000..0df4aa99
--- /dev/null
+++ b/ElectronNET.API/Entities/ToDataUrlOptions.cs
@@ -0,0 +1,13 @@
+namespace ElectronNET.API.Entities
+{
+ ///
+ ///
+ ///
+ public class ToDataUrlOptions
+ {
+ ///
+ /// Gets or sets the scalefactor
+ ///
+ public float ScaleFactor { get; set; } = 1.0f;
+ }
+}
diff --git a/ElectronNET.API/Entities/ToPNGOptions.cs b/ElectronNET.API/Entities/ToPNGOptions.cs
new file mode 100644
index 00000000..f4e36b10
--- /dev/null
+++ b/ElectronNET.API/Entities/ToPNGOptions.cs
@@ -0,0 +1,13 @@
+namespace ElectronNET.API.Entities
+{
+ ///
+ ///
+ ///
+ public class ToPNGOptions
+ {
+ ///
+ /// Gets or sets the scalefactor
+ ///
+ public float ScaleFactor { get; set; } = 1.0f;
+ }
+}
diff --git a/ElectronNET.Host/api/clipboard.js b/ElectronNET.Host/api/clipboard.js
index 610e072e..f32c6c7d 100644
--- a/ElectronNET.Host/api/clipboard.js
+++ b/ElectronNET.Host/api/clipboard.js
@@ -48,5 +48,21 @@ module.exports = (socket) => {
socket.on('clipboard-write', (data, type) => {
electron_1.clipboard.write(data, type);
});
+ socket.on('clipboard-readImage', (type) => {
+ const image = electron_1.clipboard.readImage(type);
+ electronSocket.emit('clipboard-readImage-Completed', { 1: image.toPNG().toString('base64') });
+ });
+ socket.on('clipboard-writeImage', (data, type) => {
+ var data = JSON.parse(data);
+ const ni = electron_1.nativeImage.createEmpty();
+ for (var i in data) {
+ var scaleFactor = i;
+ var bytes = data[i];
+ var buff = Buffer.from(bytes, 'base64');
+ ni.addRepresentation({ scaleFactor: scaleFactor, buffer: buff });
+ }
+
+ electron_1.clipboard.writeImage(ni, type);
+ });
};
//# sourceMappingURL=clipboard.js.map
\ No newline at end of file
diff --git a/ElectronNET.Host/api/clipboard.ts b/ElectronNET.Host/api/clipboard.ts
index f0f92c10..0cbca39f 100644
--- a/ElectronNET.Host/api/clipboard.ts
+++ b/ElectronNET.Host/api/clipboard.ts
@@ -1,4 +1,4 @@
-import { clipboard } from 'electron';
+import { clipboard, nativeImage } from 'electron';
let electronSocket;
export = (socket: SocketIO.Socket) => {
@@ -60,4 +60,22 @@ export = (socket: SocketIO.Socket) => {
socket.on('clipboard-write', (data, type) => {
clipboard.write(data, type);
});
+
+ socket.on('clipboard-readImage', (type) => {
+ var image = clipboard.readImage(type);
+ electronSocket.emit('clipboard-readImage-Completed', { 1: image.toPNG().toString('base64') });
+ });
+
+ socket.on('clipboard-writeImage', (data, type) => {
+ var data = JSON.parse(data);
+ const ni = nativeImage.createEmpty();
+ for (var i in data) {
+ var scaleFactor = i;
+ var bytes = data[i];
+ var buff = Buffer.from(bytes, 'base64');
+ ni.addRepresentation({ scaleFactor: +scaleFactor, buffer: buff });
+ }
+
+ clipboard.writeImage(ni, type);
+ });
};
diff --git a/ElectronNET.WebApp/Controllers/ClipboardController.cs b/ElectronNET.WebApp/Controllers/ClipboardController.cs
index 27f8d9e1..a290236a 100644
--- a/ElectronNET.WebApp/Controllers/ClipboardController.cs
+++ b/ElectronNET.WebApp/Controllers/ClipboardController.cs
@@ -1,6 +1,11 @@
-using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Drawing;
+using System.IO;
+using Microsoft.AspNetCore.Mvc;
using ElectronNET.API;
using System.Linq;
+using ElectronNET.API.Entities;
+using Newtonsoft.Json;
namespace ElectronNET.WebApp.Controllers
{
@@ -23,6 +28,19 @@ public IActionResult Index()
var mainWindow = Electron.WindowManager.BrowserWindows.First();
Electron.IpcMain.Send(mainWindow, "paste-from", pasteText);
});
+
+ Electron.IpcMain.On("copy-image-to", (test) =>
+ {
+ var nativeImage = NativeImage.CreateFromDataURL(test.ToString());
+ Electron.Clipboard.WriteImage(nativeImage);
+ });
+
+ Electron.IpcMain.On("paste-image-to", async test =>
+ {
+ var nativeImage = await Electron.Clipboard.ReadImageAsync();
+ var mainWindow = Electron.WindowManager.BrowserWindows.First();
+ Electron.IpcMain.Send(mainWindow, "paste-image-from", JsonConvert.SerializeObject(nativeImage));
+ });
}
return View();
diff --git a/ElectronNET.WebApp/Views/Clipboard/Index.cshtml b/ElectronNET.WebApp/Views/Clipboard/Index.cshtml
index 77e3098d..99264763 100644
--- a/ElectronNET.WebApp/Views/Clipboard/Index.cshtml
+++ b/ElectronNET.WebApp/Views/Clipboard/Index.cshtml
@@ -8,7 +8,7 @@
The Electron.Clipboard provides methods to perform copy and paste operations.
This module also has methods for copying text as markup (HTML) to the clipboard.
-
+
You find the sample source code in Controllers\ClipboardController.cs.
@@ -90,24 +90,206 @@ pasteBtn.addEventListener('click', () => {
-
diff --git a/ElectronNET.WebApp/wwwroot/assets/css/demo.css b/ElectronNET.WebApp/wwwroot/assets/css/demo.css
index 96afc4bd..4ffa4a1a 100644
--- a/ElectronNET.WebApp/wwwroot/assets/css/demo.css
+++ b/ElectronNET.WebApp/wwwroot/assets/css/demo.css
@@ -203,3 +203,7 @@
font-weight: 600;
}
+/* Clipboard paste image ------------------ */
+.demo-image-box {
+ padding-left: 15px;
+}
\ No newline at end of file