如何将使用javascript的位图转换为图像?
我正在构建一个Electron应用程序.需要一个颜色选择器,所以我想构建一个令人眼花style乱的颜色选择器.我得到一些暗示,robot.js和paper.js可能会有所帮助,因此我进行了检查.我想将它们组合在一起.我使用robot.js来获取
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] }
我想将此位图显示为图像(也许带有HTML img标签). 然后,我将能够为眼药水和鼠标事件侦听构建一个Raster(paper.js).
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.
感谢您的帮助!
bitmap.image.toString('base64')
https://nodejs.org/dist/latest-v6.x/docs/api/buffer.html#buffer_buf_tostring_encoding_start_end