简体   繁体   English

如何在Chrome应用中设置图像的宽度和高度?

[英]How do i set the width and height of the image in chrome app?

var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://supersweetdomainbutnotcspfriendly.com/image.png',true);
xhr.responseType = 'blob';
xhr.onload = function(e) {
var img = document.createElement('img');
img.src = window.URL.createObjectURL(this.response);
document.body.appendChild(img);
};

xhr.send();

By using this i can get the image but with default size. 通过使用这个我可以得到图像,但具有默认大小。 so please tell me how do i set the width and height of that image? 所以请告诉我如何设置图像的宽度和高度?

You can add two lines below var img = document.createElement('img'); 您可以在var img = document.createElement('img');下添加两行var img = document.createElement('img');

img.setAttribute('width', '100');
img.setAttribute('height', '100');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM