我试图使用JPEG编码器将原始数据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();
}
}
结果:
附言:这应该是我的照片:)