栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

将图像转换为javascript中的二进制数据[重复]

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

将图像转换为javascript中的二进制数据[重复]

我想用Javascript获取图像数据?回答您的问题:

// Code taken from MatthewCrumley (https://stackoverflow.com/a/934925/298479)function getbase64Image(img) {    // Create an empty canvas element    var canvas = document.createElement("canvas");    canvas.width = img.width;    canvas.height = img.height;    // Copy the image contents to the canvas    var ctx = canvas.getContext("2d");    ctx.drawImage(img, 0, 0);    // Get the data-URL formatted image    // Firefox supports PNG and JPEG. You could check img.src to guess the    // original format, but be aware the using "image/jpg" will re-enpre the image.    var dataURL = canvas.toDataURL("image/png");    return dataURL.replace(/^data:image/(png|jpg);base64,/, "");}

img
标签传递给此功能。它将以base64编码返回图像。但是它将被重新编码。因此,您无法访问原始图像数据。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/402631.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号