I know I need to assemble a NativeImage object to write it to the clipboard with clipboard.writeImage(image)
Does any kind soul know how I might access the contents.copyImageAt(x, y) function from within a plugin? It seems from reading the webContents docs that I need to import BrowserWindow but I don’t know how to access the contents. object for the view that Obsidian has already created.
The “solution” I came up with before was to grab the properties of the clicked element and literally read the file from disk or re-download the image again… embarrassingly inefficient and obviously doesn’t work if you’re offline or the webserver has died
There must be a way to just copy the blob / base64 image data off the canvas and shove it into the clipboard without reaching out to the filesystem or making http requests…
Another thought is to create a new (hidden) BrowserWindow instance so I could get at the image element directly via webContents API. Not sure if this is the “right” approach? @Licat any guidance would be immensely appreciated.
The buffer would be the image data you’re trying to copy - you might need to convert from a browser Uint8Array/ArrayBuffer to a node Buffer object using Buffer.from(arrayBuffer), where the arrayBuffer is what you get from vault.readBinary(file).