简体   繁体   English

将BufferedImage或ImageIO转换为ByteBuffer

[英]Converting BufferedImage or ImageIO to ByteBuffer

I read a image through BufferedImage get its RGB value, Now for writing the image back, instead of using the ImageIO, I have to write the Image in HDFS(Hadoop Distributed File System). 我通过BufferedImage读取图像以获取其RGB值,现在要写回图像,而不是使用ImageIO,必须将图像写到HDFS(Hadoop分布式文件系统)中。 Now I have only one option to use that is using FSDataOutputStream to write. 现在,我只有一个选项可以使用,即使用FSDataOutputStream进行写入。 So Is it possible to convert the RGB values from the buffered image to ByteBuffer class in Java?? 那么是否可以将RGB值从缓冲图像转换为Java中的ByteBuffer类? Pls.Help Pls.Help

BufferedImage originalImage = ImageIO.read(new File("c:\\image\\mypic.jpg"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write( originalImage, "jpg", baos );
baos.flush();
byte[] imageInByte = baos.toByteArray();
baos.close();
ByteBuffer buf = ByteBuffer.wrap(imageInByte);

Source: http://jaypthakkar.blogspot.de/2014/01/convert-bufferedimage-to-bytebuffer.html 资料来源: http : //jaypthakkar.blogspot.de/2014/01/convert-bufferedimage-to-bytebuffer.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM