【发布时间】:2012-09-16 13:39:43
【问题描述】:
我尝试使用 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();
}
}
结果:
PS 这应该是我的照片顺便说一句:)
【问题讨论】:
-
我也有同样的问题。你找到解决办法了吗?
-
不,目前我正在客户端进行所有编码,但处理时间很长
-
对我来说不管是客户端还是服务器,你现在使用什么语言和技术?
-
我在客户端使用 Flex Mobile,我正在使用 ActionScript 进行编码。如果它适合你,我可以给你(这对我来说不是最好的解决方案,因为它需要一段时间在移动设备上对 ByteArray 进行编码)
-
你能不能把它发给我(在 ehsunbehravesh dot com 发帖)它可能会给我一些想法。
标签: java image apache-flex jpeg flex-mobile