window把图片转成blob-尊龙游戏旗舰厅官网
var img = "./bigimg.jpg";//imgurl 就是你的图片路径
function getbase64image(img) {
var canvas = document.createelement("canvas");
canvas.width = img.width;
canvas.height = img.height;
var ctx = canvas.getcontext("2d");
ctx.drawimage(img, 0, 0, img.width, img.height);
var ext = img.src.substring(img.src.lastindexof(".") 1).tolowercase();
var dataurl = canvas.todata;
return dataurl;
}
var image = new image();
image.src = img;
image.onload = function(){
var base64 = getbase64image(image);
var type = "image/jpg";
console.log(base64);
var conversions = base64toblob(base64, type);
console.log(conversions)
window.url = window.url || window.webkiturl;
var url = window.url.createobject;
console.log(url,'url')
document.getelementbyid('img').src = url
}
function base64toblob(urldata, type) {
var arr = urldata.split(',');
var mime = arr[0].match(/:(.*?);/)[1] || type;
// 去掉url的头,并转化为byte
var bytes = window.atob(arr[1]);
// 处理异常,将ascii码小于0的转换为大于0
var ab = new arraybuffer(bytes.length);
// 生成视图(直接针对内存):8位无符号整数,长度1个字节
var ia = new uint8array(ab);
for (var i = 0; i < bytes.length; i ) {
ia[i] = bytes.charcodeat(i);
}
return new blob([ab], {
type: mime
});
}
与50位技术专家面对面20年技术见证,附赠技术全景图总结
以上是尊龙游戏旗舰厅官网为你收集整理的window把图片转成blob_将图片转成base64,再将base64转成blob的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇:
- 下一篇: