Zau*_*yev 9 java apache-flex jpeg image flex-mobile
我试图使用JPEGEncoder将原始数据ByteArray转换为JPEG格式,但它在移动设备上的速度太慢(我在移动设备上测试过它).我怎样才能在java中做同样的事情?我将原始数据字节发送到java并使用java将其编码为JPEG - 我尝试将它们中的一些作为com.sun.*下的JpegImageEncoder.但它在jdk7中被折旧.我如何在java中执行此操作或者已经完成此类操作的Flex移动开发人员的任何建议?
更新:我尝试了以下代码,但我得到一个奇怪的结果:
public void rawToJpeg(byte[] rawBytes, int width, int height, File outputFile){
try{
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
int count = 0;
for(int h=0;h<height;h++){
for(int w=0;w<width;w++){
bi.setRGB(w, h, rawBytes[count++]);
}
}
Graphics2D ig2 = bi.createGraphics();
Iterator imageWriters = ImageIO.getImageWritersByFormatName("jpeg");
ImageWriter imageWriter = (ImageWriter) imageWriters.next();
ImageOutputStream ios = ImageIO.createImageOutputStream(outputFile);
imageWriter.setOutput(ios);
imageWriter.write(bi);
}catch(Exception ex){
ex.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
结果: 
PS它应该是我的照片顺便说一句:)
为什么不使用ByteArrayInputStreamwith ImageIO?
您可以在API中找到有关 ImageIO 的更多信息。
public static void rawToJpeg(byte[] bytes, File outputFile) {
try {
BufferedImage img = ImageIO.read(new ByteArrayInputStream(bytes));
ImageIO.write(img, "jpg", outputFile);
} catch (IOException e) {
// Handle exception
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6239 次 |
| 最近记录: |