我已经制作了一个对象,其中我存储了用户的姓名,年龄,电子邮件和他上传的图像。我想显示他上传的图片在一个div(比方说),我不知道如何做这件事。我已经尝试过了:
$(function () {
$('img').load(function () {
var canvas = document.createElement("canvas");
canvas.width = this.width;
canvas.height = this.height;
// Copy the image contents to the canvas
var ctx = canvas.getContext("2d");
ctx.drawImage(this, 0, 0);
localStorage[this.id] = canvas.toDataURL("image/png");
})
})但是如何使用javascript或jquery来显示这个图像呢?(没有任何插件)我有5个这样的对象显示在页面上。任何解决方案都会有所帮助。谢谢
发布于 2014-10-25 02:33:41
尝尝这个
var imgCanvas = document.createElement("canvas"),
imgContext = imgCanvas.getContext("2d");
// Make sure canvas is as big as the picture
imgCanvas.width = this.width;
imgCanvas.height = this.height;
// Draw image into canvas element
imgContext.drawImage(image, 0, 0, imgCanvas.width,imgCanvas.height);
// Save image as a data URL
imgInfom = imgCanvas.toDataURL("image/png");
localStorage.setItem("imgInfo",imgInfom);
document.body.style.background = 'url('+imgInfom+')';在这里我显示的图像作为身体的背景图像,你也可以使用其他选项。
https://stackoverflow.com/questions/11228159
复制相似问题