How to convert a bitmap with javascript to an image?

五迷三道 提交于 2019-12-11 04:59:01

问题


I am building an Electron app. There is a need to have a color picker so I want to build an eye-drop style color picker. I got some hints that robot.js and paper.js might be helpful so I checked them. I'd like to, kind of, combine them together. I use robot.js to get the screen capture with a format of

bitmap {
  width: 2560,
  height: 1600,
  byteWidth: 10240,
  bitsPerPixel: 32,
  bytesPerPixel: 4,
  image: <Buffer d0 d0 cd ff d0 d0 cd ff d0 d0 cd ff d0 d0 cd ff d0 d0 cd ff d0 d0 cd ff d0 d0 cd ff d0 cf cd ff cf cf cd ff cf cf cd ff cf cf cd ff cf cf cd ff cf cf ... >,
  colorAt: [Function] }

I'd like to display this bitmap as an image (maybe with a HTML img tag). Then I will be able to build a Raster (paper.js) for the eye drop and mouse event listening.

However, I did not find a way to convert this image buffer to an actual image.

Any help is appreciate!


回答1:


bitmap.image.toString('base64')

https://nodejs.org/dist/latest-v6.x/docs/api/buffer.html#buffer_buf_tostring_encoding_start_end



来源:https://stackoverflow.com/questions/41499872/how-to-convert-a-bitmap-with-javascript-to-an-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!