欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

解析: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]);
        }
    }