obsidian-notes/代码/DataURL解码.md
CSSC-WORK\murmur 3e6078442b init version
2024-04-15 11:19:57 +08:00

31 lines
1.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: DataURL解码
updated: 2022-01-11 08:10:04Z
created: 2022-01-11 07:55:24Z
tags:
- aardio
- 代码块
---
原mybase笔记中的图片大量采用DataURL编码这会生成大量字符故不适合MarkDown的编辑方式需要转换回图片格式。
经测试joplin会自动转换剪贴板中的图像为附件并将链接插入正文于是只需将原DataURL转回图片存于剪切板即可。
笔记中通常有多图为方便快速转换程序支持自动提取并预览切换图片时时自动复制到剪贴板在joplin中直接粘贴即可。
源码如下:
[DataURL转剪贴板.aardio](../_resources/DataURL转剪贴板.aardio)
核心代码为:
```c
picarr = {}; //读剪贴板前需重置
var pattern = "data\:image\/\w+;base64,(\S+)"""//最后的"代表base64字符结束位置
for str in string.gmatch(strInClip, pattern ){//匹配DataURL编码
if(!str) return ;
table.push(picarr,str)
}
var img = crypt.decodeBin(picarr[index]); //解码
win.clip.writeBitmap(gdip.bitmap(img).copyHandle())//写剪贴板
winform.picturebox.background = gdip.bitmap(img)//预览
```
#aardio
#代码块