掃二維碼與項目經(jīng)理溝通
我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流

圖像解碼就是將所支持格式的存檔圖片解碼成統(tǒng)一的 PixelMap 圖像,用于后續(xù)圖像顯示或其他處理,比如旋轉(zhuǎn)、縮放、裁剪等。當前支持格式包括 JPEG、PNG、GIF、HEIF、WebP、BMP。
ImageSource 主要用于圖像解碼。
| 接口名 | 描述 |
|---|---|
| create(String pathName, SourceOptions opts) | 從圖像文件路徑創(chuàng)建圖像數(shù)據(jù)源。 |
| create(InputStream is, SourceOptions opts) | 從輸入流創(chuàng)建圖像數(shù)據(jù)源。 |
| create(byte[] data, SourceOptions opts) | 從字節(jié)數(shù)組創(chuàng)建圖像源。 |
| create(byte[] data, int offset, int length, SourceOptions opts) | 從字節(jié)數(shù)組指定范圍創(chuàng)建圖像源。 |
| create(File file, SourceOptions opts) | 從文件對象創(chuàng)建圖像數(shù)據(jù)源。 |
| create(FileDescriptor fd, SourceOptions opts) | 從文件描述符創(chuàng)建圖像數(shù)據(jù)源。 |
| createIncrementalSource(SourceOptions opts) | 創(chuàng)建漸進式圖像數(shù)據(jù)源。 |
| createIncrementalSource(IncrementalSourceOptions opts) | 創(chuàng)建漸進式圖像數(shù)據(jù)源,支持設置漸進式數(shù)據(jù)更新模式。 |
| createPixelmap(DecodingOptions opts) | 從圖像數(shù)據(jù)源解碼并創(chuàng)建 PixelMap 圖像。 |
| createPixelmap(int index, DecodingOptions opts) | 從圖像數(shù)據(jù)源解碼并創(chuàng)建 PixelMap 圖像,如果圖像數(shù)據(jù)源支持多張圖片的話,支持指定圖像索引。 |
| updateData(byte[] data, boolean isFinal) | 更新漸進式圖像源數(shù)據(jù)。 |
| updateData(byte[] data, int offset, int length, boolean isFinal) | 更新漸進式圖像源數(shù)據(jù),支持設置輸入數(shù)據(jù)的有效數(shù)據(jù)范圍。 |
| getImageInfo() | 獲取圖像基本信息。 |
| getImageInfo(int index) | 根據(jù)特定的索引獲取圖像基本信息。 |
| getSourceInfo() | 獲取圖像源信息。 |
| release() | 釋放對象關(guān)聯(lián)的本地資源。 |
ImageSource.SourceOptions srcOpts = new ImageSource.SourceOptions();
srcOpts.formatHint = "image/png";
String pathName = "/path/to/image.png";
ImageSource imageSource = ImageSource.create(pathName, srcOpts);
ImageSource imageSourceNoOptions = ImageSource.create(pathName, null); // 普通解碼疊加旋轉(zhuǎn)、縮放、裁剪
ImageSource.DecodingOptions decodingOpts = new ImageSource.DecodingOptions();
decodingOpts.desiredSize = new Size(100, 2000);
decodingOpts.desiredRegion = new Rect(0, 0, 100, 100);
decodingOpts.rotateDegrees = 90;
PixelMap pixelMap = imageSource.createPixelmap(decodingOpts);
// 普通解碼
PixelMap pixelMapNoOptions = imageSource.createPixelmap(null); ImageSource.SourceOptions srcOpts = new ImageSource.SourceOptions();
srcOpts.formatHint = "image/jpeg";
ImageSource.IncrementalSourceOptions incOpts = new ImageSource.IncrementalSourceOptions();
incOpts.opts = srcOpts;
incOpts.mode = ImageSource.UpdateMode.INCREMENTAL_DATA;
imageSource = ImageSource.createIncrementalSource(incOpts); // 獲取到一定的數(shù)據(jù)時嘗試解碼
imageSource.updateData(data, 0, bytes, false);
ImageSource.DecodingOptions decodingOpts = new ImageSource.DecodingOptions();
PixelMap pixelMap = imageSource.createPixelmap(decodingOpts);
// 更新數(shù)據(jù)再次解碼,重復調(diào)用直到數(shù)據(jù)全部更新完成
imageSource.updateData(data, 0, bytes, false);
PixelMap pixelMap = imageSource.createPixelmap(decodingOpts);
// 數(shù)據(jù)全部更新完成時需要傳入isFinal為true
imageSource.updateData(data, 0, bytes, true);
PixelMap pixelMap = imageSource.createPixelmap(decodingOpts);
我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流