97干视频,99国产精品懂色,亚洲精品99久久久久中文字幕,伊人五月丁香综合AⅤ,国产精品成人免费999

  您的位置:華清遠(yuǎn)見(jiàn)教育科技集團(tuán) >> 新聞動(dòng)態(tài) >> Android資料 >> Android圖像解碼的實(shí)現(xiàn)  
 
Android圖像解碼的實(shí)現(xiàn)
分享到:

在智能機(jī)中,圖像處理多通過(guò)專有DSP進(jìn)行相關(guān)的編解碼。為了顯示圖像,需要對(duì)圖像進(jìn)行解碼,在智能終端中,具體的解碼過(guò)程通常都需要借助aDSP來(lái)實(shí)現(xiàn)。下圖所示為圖像的解碼過(guò)程。

圖像解碼過(guò)程
圖像解碼過(guò)程

在Android中,圖像的解碼均是基于ImageDecoder基類的,為了進(jìn)行解碼,需要通過(guò)BitmapFactory:: decodeStream()方法對(duì)輸入流進(jìn)行處理。下面是BitmapFactory:: decodeStream()方法的實(shí)現(xiàn):

代碼5-10 BitmapFactory:: decodeStream()的實(shí)現(xiàn)

public static Bitmap decodeStream(InputStream is, Rect outPadding, Options opts)
    {
      if (is==null) {
        return null;
      }
      if (!is.markSupported()) {
        is=new BufferedInputStream(is, 16 * 1024);//創(chuàng)建一個(gè)緩沖
      }
      is.mark(1024);
      Bitmap bm;
      if (is instanceof AssetManager.AssetInputStream) {
        return null;
      } else {
        try {
          bm=new Bitmap(is); //進(jìn)行解碼
      } catch (IOException e) {
          return null;
        }
      }
      return finishDecode(bm, outPadding, opts);
    }
    private static Bitmap finishDecode(Bitmap bm, Rect outPadding, Options opts) {
      if (bm==null || opts==null) {
        return bm;
      }
      final int density=opts.inDensity;
      if (density==0) {
        return bm;
      }
      bm.setDensity(density); //設(shè)置密度
      final int targetDensity=opts.inTargetDensity;
      if (targetDensity==0 || density==targetDensity
          || density==opts.inScreenDensity) {
        return bm;
      }
      byte[] np=bm.getNinePatchChunk();
      final boolean isNinePatch=false; //np != null && NinePatch.isNinePatchChunk(np);
      if (opts.inScaled || isNinePatch) {
        float scale=targetDensity / (float)density; //伸縮因子
        final Bitmap oldBitmap=bm;
        bm=Bitmap.createScaledBitmap(oldBitmap, (int) (bm.getWidth() * scale + 0.5f),(int) (bm.getHeight() * scale + 0.5f), true);//創(chuàng)建伸縮圖像
        oldBitmap.recycle();
        if (isNinePatch) {
          bm.setNinePatchChunk(np);
        }
        bm.setDensity(targetDensity); //設(shè)置密度
      }
      return bm;
    }

終的解碼工作則是通過(guò)SGL引擎來(lái)進(jìn)行的,關(guān)于SGL引擎的更多內(nèi)容,可以參考之前的免費(fèi)資Android Skia 渲染概述Android Skia圖形渲染等內(nèi)容。

 更多相關(guān)文章

·Android Camera 參數(shù)的設(shè)置
·Android Camera的HAL接口
·Android中Camera數(shù)據(jù)的處理
·Android Camera拍照源碼分析
·Android Camera原生服務(wù)架構(gòu)