转换图像为字节code在JavaScript IE8 [英] convert image to byte code in javascript IE8

查看:412
本文介绍了转换图像为字节code在JavaScript IE8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在图片(PNG)转换为字节code在Javascript中。我用这个code,但在IE8有这code没有用,因为有不支持canvas元素的IE8。

How to convert an Image(png) to byte code in Javascript. 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.

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;
} 

是任何其他方式获得的图像字节code在IE8。我需要无论是从形象到HTML页面的base64字节code或从任何图像的URL的base64字节code。

Is any other way to get image byte code in IE8. I need either from Image to base64 byte code in a html page or from any image url base64 byte code.

我的图片网址像<一个href=\"http://chart.googleapis.com/chart?cht=bvg&chs=260x180&chxt=x,y&chxl=1%3a%7C%240%7C%24500%7C%241000%7C%241500%7C%242000%7C%242500%7C0%3a%7C0-4%7C5-18%7C19-45%7C46-64%7C65%2b&chdlp=r&chco=3399FF,C0C0C0&chxr=1,0,1481&chbh=a,0,15&chd=t:202,216,248,517,1481%7C130,0,458,623,680&chg=0,20,0&chxs=1N%2acUSD,,13,0,_&chds=0,2500\"相对=nofollow>这是有任何其他方式来获得在javascript中的图像字节code。

My image url is like this is there any other way to get image byte code in javascript.

推荐答案

答案很简单,可惜你不能 - 开箱

Simple answer is unfortunately you can't - out of the box.

正如你所说,IE8不支持canvas元素,所以没有办法提取图像数据的字节数,你会需要通过画布去,然后用 toDataURL getImageData

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,使您可以使用基本功能,如excanvas。然而,这并不支持像素提取与上述两个metods

There are poly-fills for IE8 that allows you to use the basic functions such as excanvas. This however does not support pixel extraction as with the two above mentioned metods.

有两种解决方法:


  1. 使用服务器:发送图像到服务器,并处理它有

  2. 基于Flash的使用帆布聚填充,让你可以做到这一点。

对于后一点有几个选项,比如这一个:结果
http://flashcanvas.net/

For the latter point there are a few options such as this one:
http://flashcanvas.net/

这篇关于转换图像为字节code在JavaScript IE8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆