如何使用Dart将图像从剪贴板粘贴到Canvas元素? [英] How can I paste an image from the clipboard onto a Canvas element using Dart?
本文介绍了如何使用Dart将图像从剪贴板粘贴到Canvas元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Dart开发一个个人白板Chrome应用程式,有时能够快速复制和粘贴图像(例如,从演示文稿,图表或讲义中的幻灯片),以便我可以添加笔记
I'm using Dart to develop a personal whiteboard Chrome app and it is sometimes useful to be able to quickly copy and paste an image (e.g. a slide from a presentation, a diagram or a handout) so that I can add notes over the image while teaching a class or giving a presentation.
如何将存储在剪贴板上的图片粘贴到Dart中的canvas元素上?
How can I paste an image stored on the clipboard onto a canvas element in Dart?
推荐答案
实际上,这个问题对于JS 几乎可以直接应用。 Dart翻译可能如下所示:
Actually, this answer to the same question for JS is almost directly applicable. A Dart translation might look something like:
import 'dart:html';
void main() {
var can = new CanvasElement()
..width = 600
..height = 600
;
var con = can.getContext('2d');
document.onPaste.listen((e) {
var blob = e.clipboardData.items[0].getAsFile();
var reader = new FileReader();
reader.onLoad.listen((e) {
var img = new ImageElement()
..src = (e.target as FileReader).result;
img.onLoad.listen((_) {
con.drawImage(img, 0, 0);
});
});
reader.readAsDataUrl(blob);
});
document.body.children.add(can);
}
这篇关于如何使用Dart将图像从剪贴板粘贴到Canvas元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文