2013-10-15 48 views
0

我正在用Spring开发一个RESTful API,其中一些用户可以上传他们在移动设备中绘制的一些图像。移动应用程序以.png格式发送图像,我需要从中生成一个位图,以便在Delphi中进一步处理。我一直在玩ImageIO类,但是在指定.bmp格式并写入新文件时似乎并没有这样做。有没有一些图书馆做这些图像转换?现在应该是一个解决的问题,但我对图像处理并不熟悉。PNG到位图文件转换

感谢

+0

http://stackoverflow.com/questions/13110159/reading-and-storing-a-bmp-file-in-java – UDPLover

+0

PNG图像位图和Delphi可以读取PNG文件,显然。那么'.bmp'文件? – reinierpost

+0

@reinierpost德尔福部分由另一个合作伙伴领导,他期望它完全是一个.bmp文件 – jarandaf

回答

0

这应该工作:

//Create file for the source 
File input = new File("c:/temp/image.png"); 

//Read the file to a BufferedImage 
BufferedImage image = ImageIO.read(input); 

//Create a file for the output 
File output = new File("c:/temp/image.bmp"); 

//Write the image to the destination as a BMP 
ImageIO.write(image, "bmp", output); 
+0

我实际上已经尝试过这种解决方案,但没有取得太大的成功。我收到.png文件,但试图用ImageIO.write方法编写时,没有生成文件 – jarandaf

+0

您是否遇到任何异常?你有权限写这个文件吗? – Ezzored

+0

不会引发异常,是的,我有权在目录中写入文件。我唯一想到的就是png文件被破坏了,因此没有执行文件转换,但是应该抛出一些异常 – jarandaf