31 lines
1.1 KiB
Markdown
31 lines
1.1 KiB
Markdown
|
---
|
|||
|
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
|
|||
|
#代码块
|