解析:android 如何从JPEG生成BufferedImage
更新时间:2013年06月17日 08:54:14 作者:
本篇文章是对在android中,如何从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]);
}
}
复制代码 代码如下:
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]);
}
}
相关文章
ActivityManagerService广播注册与发送示例解析
这篇文章主要为大家介绍了ActivityManagerService广播注册与发送示例解析,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2023-03-03android通过jxl读excel存入sqlite3数据库
本文主要介绍了android通过jxl去读excel的内容,然后存入sqlite3数据库表,需要用到jxl的jar包和sqlite 的jar包,图片是excel的数据格式,需要的朋友可以参考下2014-03-03
最新评论