JPEG生成BufferedImage 解析:android 怎样从JPEG生成BufferedImage
人气:0想了解解析:android 怎样从JPEG生成BufferedImage的相关内容吗,在本文为您仔细讲解JPEG生成BufferedImage的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:JPEG,生成,BufferedImage,下面大家一起来学习吧。
如下所示:复制代码 代码如下:
private void readImage(String filename) throws FileNotFoundException, IOException {
FileInputStream fIn = new FileInputStream(filename);
//需要替换这边的两句:
JPEGImageDecoder jpeg_decode = JPEGCodec.createJPEGDecoder(fIn);
BufferedImage image = jpeg_decode.decodeAsBufferedImage();
width = image.getWidth();
height = image.getHeight();
int[] rgbdata = new int[width * height];
image.getRGB(0,0,width,height,rgbdata,0,width);
bytes = new byte[rgbdata.length];
doubles = new double[rgbdata.length];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) (rgbdata[i] & 0xFF);
doubles[i] = (double)(rgbdata[i]);
}
}
加载全部内容