av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

創(chuàng)新互聯(lián)鴻蒙OS教程:鴻蒙OS 圖像解碼開發(fā)指導

場景介紹

圖像解碼就是將所支持格式的存檔圖片解碼成統(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)的本地資源。

普通解碼開發(fā)步驟

  1. 創(chuàng)建圖像數(shù)據(jù)源 ImageSource 對象,可以通過 SourceOptions 指定數(shù)據(jù)源的格式信息,此格式信息僅為給解碼器的提示,正確提供能幫助提高解碼效率,如果不設置或設置不正確,會自動檢測正確的圖像格式。不使用該選項時,可以將 create 接口傳入的 SourceOptions 設置為 null。
   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);

  1. 設置解碼參數(shù),解碼獲取 PixelMap 圖像對象,解碼過程中同時支持圖像處理操作。設置 desiredRegion 支持按矩形區(qū)域裁剪,如果設置為全 0,則不進行裁剪。設置 desiredSize 支持按尺寸縮放,如果設置為全 0,則不進行縮放。設置 rotateDegrees 支持旋轉(zhuǎn)角度,以圖像中心點順時針旋轉(zhuǎn)。如果只需要解碼原始圖像,不使用該選項時,可將給 createPixelMap 傳入的 DecodingOptions 設置為 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);

  1. 解碼完成獲取到 PixelMap 對象后,可以進行后續(xù)處理,比如渲染顯示等。

漸進式解碼開發(fā)步驟

  1. 創(chuàng)建漸進式圖像數(shù)據(jù)源 ImageSource 對象,可以通過 SourceOptions 指定數(shù)據(jù)源的格式信息,此格式信息僅為提示,如果填寫不正確,會自動檢測正確的圖像格式,使用 IncrementalSourceOptions 指定圖像數(shù)據(jù)的更新方式為漸進式更新。
   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);

  1. 漸進式更新數(shù)據(jù),在未獲取到全部圖像時,支持先更新部分數(shù)據(jù)來嘗試解碼,更新數(shù)據(jù)時設置 isFinal 為 false,當獲取到全部數(shù)據(jù)后,最后一次更新數(shù)據(jù)時設置 isFinal 為 true,表示數(shù)據(jù)更新完畢。設置解碼參數(shù)同普通解碼。
   // 獲取到一定的數(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);

  1. 解碼完成獲取到 PixelMap 對象后,可以進行后續(xù)處理,比如渲染顯示等。

文章標題:創(chuàng)新互聯(lián)鴻蒙OS教程:鴻蒙OS 圖像解碼開發(fā)指導
當前地址:http://uogjgqi.cn/article/cdgojci.html
掃二維碼與項目經(jīng)理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流