最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Draw image from pixel data arrays - Stack Overflow

programmeradmin0浏览0评论

If I have an array of pixel data in JavaScript, is there a good way to display it on an HTML page?

  • On recent versions of Safari and Firefox, I can make a <canvas> element and use putImageData to display the pixels, but ideally a solution could work on older versions as well and more importantly, work on Internet Explorer.
  • Another solution which seems more tangible could be to encode the pixels into a standard image format and create a data: URI with the pixels and set that as the src of an <img> element. Unfortunately, it seems like most image formats are plex and I'm having a hard time finding a simple one that can do the job (BMP looks like a possibility but does not work on Safari). Also, versions of Internet Explorer before IE 8 don't support data: URIs at all.

I doubt any exist, but does anyone know of image libraries for JavaScript that can generate image in a standard format? Is there a way to replicate the functionality of a data: URI in IE 7?

If I have an array of pixel data in JavaScript, is there a good way to display it on an HTML page?

  • On recent versions of Safari and Firefox, I can make a <canvas> element and use putImageData to display the pixels, but ideally a solution could work on older versions as well and more importantly, work on Internet Explorer.
  • Another solution which seems more tangible could be to encode the pixels into a standard image format and create a data: URI with the pixels and set that as the src of an <img> element. Unfortunately, it seems like most image formats are plex and I'm having a hard time finding a simple one that can do the job (BMP looks like a possibility but does not work on Safari). Also, versions of Internet Explorer before IE 8 don't support data: URIs at all.

I doubt any exist, but does anyone know of image libraries for JavaScript that can generate image in a standard format? Is there a way to replicate the functionality of a data: URI in IE 7?

Share Improve this question asked Jun 23, 2010 at 0:14 Sophie AlpertSophie Alpert 143k36 gold badges226 silver badges243 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 3

Canvas is a good solution, for-cross browser support see Mark Pilgrim's excellent tutorial. Specifically, the "What about IE?" section and using ExplorerCanvas. You can use and create data: URIs in the PNG and JPEG formats with canvas.

Does PNG format work for your targets? If so PNGlib looks pretty good.

Also, JS JPEG Encoder looks good but it takes as input the returned value of Canvas.getImageData().

Don't know what you can do to support IE 7 though.

Check you Raphaël - http://raphaeljs./

While this may be slow, and it is not the intended use of the library, it will work with support for browsers you're interested in.

Maybe check out fxCanvas http://burzak./pro/fxcanvas/

I think they implement even ‘putImageData‘ in IE using Flash.

发布评论

评论列表(0)

  1. 暂无评论