解析: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雙緩沖技術實例詳解
- logcat命令使用方法和查看android系統(tǒng)日志緩沖區(qū)內(nèi)容的方法
- Android中的Bitmap緩存池使用詳解
- android開發(fā)教程之清除android數(shù)據(jù)緩存示例(清除本地數(shù)據(jù)緩存)
- android中圖片的三級緩存cache策略(內(nèi)存/文件/網(wǎng)絡)
- Android中加載網(wǎng)絡資源時的優(yōu)化可使用(線程+緩存)解決
- android異步加載圖片并緩存到本地實現(xiàn)方法
- android上的一個網(wǎng)絡接口和圖片緩存框架enif簡析
- Android在JNI中使用ByteBuffer的方法
相關文章
ActivityManagerService廣播注冊與發(fā)送示例解析
這篇文章主要為大家介紹了ActivityManagerService廣播注冊與發(fā)送示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-03-03android通過jxl讀excel存入sqlite3數(shù)據(jù)庫
本文主要介紹了android通過jxl去讀excel的內(nèi)容,然后存入sqlite3數(shù)據(jù)庫表,需要用到jxl的jar包和sqlite 的jar包,圖片是excel的數(shù)據(jù)格式,需要的朋友可以參考下2014-03-03Flutter自定義實現(xiàn)神奇動效的卡片切換視圖的示例代碼
這篇文章主要介紹了Flutter自定義實現(xiàn)神奇動效的卡片切換視圖的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-04-04