解析:android 如何从JPEG生成BufferedImage
程序员文章站
2023-10-19 13:41:05
如下所示:复制代码 代码如下:private void readimage(string filename) throws filenotfoundexcept...
如下所示:
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]);
}
}
上一篇: 解析android创建快捷方式会启动两个应用的问题
下一篇: 练气功需要注意什么 八个禁忌不得不知