通过html图像元素对象显示图像 [英] Display image through html image element object

查看:78
本文介绍了通过html图像元素对象显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

function createImage(source) {                
var pastedImage = new Image();                
pastedImage.onload = function() {

}
pastedImage.src = source;
}

函数createImage包含包含图像源的source参数。之后我创建了类Image的对象pastedImage,并在警告我获取了像 [object HTMLImageElement] 之类的html图像元素对象之后。

The function createImage contain the source parameter which contain the source of an image. After that I created the object pastedImage of class Image and after alerting that I am getting the html image element object like [object HTMLImageElement].

我的问题是如何使用该对象将图像显示到我的html页面中。我希望在onload函数后显示它。

My question is how I can display image into my html page using that object. I want to display it after onload function.

提前致谢。

推荐答案

你也可以这样做:

    function createImage(source) {
        var pastedImage = new Image();
        pastedImage.onload = function() {

 document.write('<br><br><br>Your image in canvas: <img src="'+pastedImage.src+'" height="100" width="200"/>');                      

        }
        pastedImage.src = source;        
    }​

这篇关于通过html图像元素对象显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆