解析: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]);
}
}
相關文章
Android仿QQ在狀態(tài)欄顯示登錄狀態(tài)效果
這篇文章主要介紹了Android仿QQ在狀態(tài)欄顯示登錄狀態(tài)效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-12-12
Android中ListView的幾種常見的優(yōu)化方法總結
Android中的ListView應該算是布局中幾種最常用的組件之一,本篇文章主要做了三種優(yōu)化總結,有興趣的可以了解一下。2017-02-02

