开发者

How can i convert *.raw files to *.bmp in JAVA?

开发者 https://www.devze.com 2023-02-28 11:12 出处:网络
BufferedImage image = ImageIO.read( new ByteArrayInputStream( byteArray ) ); ImageIO.write(image, \"BMP\", new File(\"filename.bmp\"));
BufferedImage image = ImageIO.read( new ByteArrayInputStream( byteArray ) );
ImageIO.write(image, "BMP", new File("filename.bmp"));

When i tried this thing [ImageIO.read( new ByteArrayInputStream( byteArray ))] returns null value so i cant create new bmp file. But this works 开发者_JS百科to convert jpg to bmp files.I have raw files and i need to convert to image. Please help me in this.


The support for readers and writers in the javax.imageio is limited, and if you dont know the format of the byte[] your are trying to convert, then propably it is not included in the list of valid image readers. Then, what you might need is the Java Advanced Imaging API, which you can find here.

These are the readers a Readers: Writers: bmp bmp jpg jpg jpeg jpeg wbmp Wbmp png png gif gif

This few lines shall help you to get this to work using JAI API

// read byte[] 
SeekableStream stream = new ByteArraySeekableStream(image);
// render stream of bytes to valid image format
RenderedImage renderedImage = JAI.create("stream", stream);
// persist image to file
JAI.create("filestore", renderedImage, filename, targetFormat);
// dont't forget to close the stream!
stream.close();


Take a look here: Java Advanced Imaging I/O Tools. The Java Image I/O Reader seems to be able to read "raw"-Files. I think that you can write them with the Java Image I/O Writer as BMP.

regards

Macs

0

精彩评论

暂无评论...
验证码 换一张
取 消