Ana*_*mar 11 java bufferedimage bitmap
我有一个程序,我使用代码捕获屏幕:
robot = new Robot();
BufferedImage img = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
Run Code Online (Sandbox Code Playgroud)
现在我想将这个BufferedImage转换为Bitmap格式并通过函数返回它以满足其他需求,而不是将其保存在文件中.有什么帮助吗?
你需要看看ImageIO.write
.
如果你想以byte[]
数组的形式得到结果,你应该使用ByteArrayOutputStream
:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(yourImage, "bmp", baos);
baos.flush();
byte[] bytes = baos.toByteArray();
baos.close();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10918 次 |
最近记录: |