Canvas Haven的创建图像将附加到HTML容器
我有画布。现在,我想制作画布的图像。我已经开发了这个功能。我有一个与正确的SRC-Attribute的图像。但是,如果我想将此图像元素附加到html-container上,则它不起作用。什么都没有发生。
我不知道为什么。 HTML容量可用,图像正确。
这是一些代码:
创建
function createPicture(canvas, container){
let dataURL = canvas.toDataURL({
width: canvas.width,
height: canvas.height,
left: 0,
top: 0,
format: 'jpeg',
});
let image = new Image();
image.setAttribute("src", dataURL);
container.append(image);
}
呼叫此功能图像的图片的函数:
createPicture(canvas, $("#test"));
在控制台中
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD…">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码对我来说很好,请参阅下面的示例
我唯一能想到的是,您将createPicture称为期望在那里的createpicture后在画布上做某事,如果您仍然遇到问题,我建议您创建一个代码代码来重现问题,并在此处将其发布在此处
检查您的开发控制台,确保您看到图像元素:
如果您看不到它,那么问题必须是容器
Your code works fine for me, see my sample below
Only thing I could think of is you are doing something on your canvas after you call the createPicture an expecting it to be there, if you still run into problems I would recommend you to create a code snippet reproducing your problem and post it here
Check on your dev console, make sure you see the image element:

If you don't see it then the problem must be the container