如何将使用javascript的位图转换为图像? [英] How to convert a bitmap with javascript to an image?

查看:126
本文介绍了如何将使用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

这篇关于如何将使用javascript的位图转换为图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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