W3Cschool
恭喜您成為首批注冊用戶
獲得88經驗值獎勵
圖像解碼就是將所支持格式的存檔圖片解碼成統(tǒng)一的 PixelMap 圖像,用于后續(xù)圖像顯示或其他處理,比如旋轉、縮放、裁剪等。當前支持格式包括 JPEG、PNG、GIF、HEIF、WebP、BMP。
ImageSource 主要用于圖像解碼。
接口名 | 描述 |
---|---|
create(String pathName, SourceOptions opts) | 從圖像文件路徑創(chuàng)建圖像數據源。 |
create(InputStream is, SourceOptions opts) | 從輸入流創(chuàng)建圖像數據源。 |
create(byte[] data, SourceOptions opts) | 從字節(jié)數組創(chuàng)建圖像源。 |
create(byte[] data, int offset, int length, SourceOptions opts) | 從字節(jié)數組指定范圍創(chuàng)建圖像源。 |
create(File file, SourceOptions opts) | 從文件對象創(chuàng)建圖像數據源。 |
create(FileDescriptor fd, SourceOptions opts) | 從文件描述符創(chuàng)建圖像數據源。 |
createIncrementalSource(SourceOptions opts) | 創(chuàng)建漸進式圖像數據源。 |
createIncrementalSource(IncrementalSourceOptions opts) | 創(chuàng)建漸進式圖像數據源,支持設置漸進式數據更新模式。 |
createPixelmap(DecodingOptions opts) | 從圖像數據源解碼并創(chuàng)建 PixelMap 圖像。 |
createPixelmap(int index, DecodingOptions opts) | 從圖像數據源解碼并創(chuàng)建 PixelMap 圖像,如果圖像數據源支持多張圖片的話,支持指定圖像索引。 |
updateData(byte[] data, boolean isFinal) | 更新漸進式圖像源數據。 |
updateData(byte[] data, int offset, int length, boolean isFinal) | 更新漸進式圖像源數據,支持設置輸入數據的有效數據范圍。 |
getImageInfo() | 獲取圖像基本信息。 |
getImageInfo(int index) | 根據特定的索引獲取圖像基本信息。 |
getSourceInfo() | 獲取圖像源信息。 |
release() | 釋放對象關聯(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);
// 普通解碼疊加旋轉、縮放、裁剪
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);
// 獲取到一定的數據時嘗試解碼
imageSource.updateData(data, 0, bytes, false);
ImageSource.DecodingOptions decodingOpts = new ImageSource.DecodingOptions();
PixelMap pixelMap = imageSource.createPixelmap(decodingOpts);
// 更新數據再次解碼,重復調用直到數據全部更新完成
imageSource.updateData(data, 0, bytes, false);
PixelMap pixelMap = imageSource.createPixelmap(decodingOpts);
// 數據全部更新完成時需要傳入isFinal為true
imageSource.updateData(data, 0, bytes, true);
PixelMap pixelMap = imageSource.createPixelmap(decodingOpts);
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: