html5中文学习网

您的位置: 首页 > android » 正文

解析:android 如何从JPEG生成BufferedImage_Android_脚本之家

[ ] 已经帮助:人解决问题
如下所示:
复制代码 代码如下:

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]);
        }
    }
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助