gpt4 book ai didi

javascript - 如何将实时图像 url 转换为 Angular blob?

转载 作者:太空狗 更新时间:2023-10-29 17:38:42 24 4
gpt4 key购买 nike

<分区>

我在 angular 7 中工作,我的要求是我需要获得 WidthHeightSize(多少 kb 或 mb)图像,我也在尝试将其转换为 blob

我试过下面的代码,但我没有得到准确的输出:

var img_url = "http://snook.ca/files/mootools_83_snookca.png";


var blob = new Blob([img_url]);

let reader = new FileReader;

reader.readAsDataURL(blob); // read file as data url
reader.onload = () => { // when file has loaded
console.log(reader.result)
var img:any = new Image();
img.src = reader.result;

img.onload = () => {

this.uploaded_image_width = img.width; //to get image width
this.uploaded_image_height = img.height; //to get image height

this.uploaded_image_url = reader.result; //to get blob image
console.log(reader.result)
};
}

当 im consoling blob 数据出错时 (console.log(reader.result)) 并且内部 img.onload 函数没有执行。

我引用了这个 fiddle 来实现这个: http://jsfiddle.net/guest271314/9mg5sf7o/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com