简体   繁体   English

将图像转换为JavaScript IE8中的字节码

[英]convert image to byte code in javascript IE8

How to convert an Image(png) to byte code in Javascript . 如何在Javascript中将Image(png)转换为字节码 I've used this code but in IE8 there is no use in this code because there is no support of canvas element in IE8. 我使用了此代码,但在IE8中没有使用此代码,因为IE8中不支持canvas元素。

function getBase64Image(){     
    p=document.getElementById("fileUpload").value;
    img1.setAttribute('src', p); 
    canvas.width = img1.width; 
    canvas.height = img1.height; 
    var ctx = canvas.getContext("2d"); 
    ctx.drawImage(img1, 0, 0); 
    var dataURL = canvas.toDataURL("image/png");alert("from getbase64 function"+dataURL );    
    return dataURL;
} 

Is any other way to get image byte code in IE8. 是否有其他方法可以在IE8中获取图像字节代码。 I need either from Image to base64 byte code in a html page or from any image url base64 byte code. 我需要从HTML页面中的Image到base64字节代码,或任何图像url base64字节代码。

My image url is like this is there any other way to get image byte code in javascript. 我的图片网址就像这样,是否有其他方法可以在javascript中获取图片字节代码。

Simple answer is unfortunately you can't - out of the box. 不幸的是,简单的答案是您不能-开箱即用。

As you say, IE8 does not support the canvas element so there is no way to extract the image data as bytes as you would need to go by the canvas and then use toDataURL or getImageData . 就像您说的那样,IE8不支持canvas元素,因此无法像通过画布然后使用toDataURLgetImageData那样将图像数据提取为字节。

There are poly-fills for IE8 that allows you to use the basic functions such as excanvas. IE8有多种填充,您可以使用基本功能(例如,挖掘工具)。 This however does not support pixel extraction as with the two above mentioned metods. 但是,这不像上述两个方法那样支持像素提取。

There are two work-arounds: 有两种解决方法:

  1. Use server: send image to server and process it there 使用服务器:将图像发送到服务器并在那里进行处理
  2. Use Flash-based canvas "poly-fills" which allow you to do this. 使用基于Flash的画布“多边形填充”,您可以执行此操作。

For the latter point there are a few options such as this one: 对于后一点,有一些这样的选择:
http://flashcanvas.net/ http://flashcanvas.net/

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

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