Notifications
Clear all
[Closed] Save bitmap to file
2 Replies
Sep 28, 2020 2:30 am
you could either save them in customattributes or in appdata
clearAllAppData rootNode
(
-- saving
bm = bitmap 128 128
rendermap (checker()) into:bm
prev_clipboard = getClipboardBitmap()
setClipboardBitmap bm
clipboard_img = (dotnetclass "System.Windows.Forms.Clipboard").GetImage()
ms = dotNetObject "system.io.memorystream"
clipboard_img.save ms (dotNetClass "System.Drawing.Imaging.ImageFormat").Png
base64 = (dotnetclass "system.convert").ToBase64String (ms.ToArray())
setAppData rootNode 42 base64
if prev_clipboard != undefined do setClipboardBitmap prev_clipboard
)
(
-- loading
base64 = getAppData rootNode 42
bytes = (dotnetclass "system.convert").FromBase64String base64 asdotnetobject:true
prev_clipboard = getClipboardBitmap()
ms = dotNetObject "system.io.memorystream" bytes 0 bytes.Length
img = (dotNetClass "System.Drawing.Image").FromStream ms
(dotnetclass "System.Windows.Forms.Clipboard").SetImage img
bm = getClipboardBitmap()
if prev_clipboard != undefined do setClipboardBitmap prev_clipboard
display bm
)