2013-05-21 45 views
1

我的程序是解碼位圖並顯示它。加載位圖並在ImageView中高效顯示

原始解碼代碼和顯示代碼在我的電腦上完美工作。

當我在我的android設備中使用代碼時,代碼也可以解碼流。

問題是ImageView中的圖像顯示效率不高。

下面

是我的代碼

我使用一個線程調用解碼功能部分,不是顯示它的ImageView

class ProcessData extends Thread{ 
    Message message; 
     String obj="run"; 
     ReadRawFileImage readMyRawData=new ReadRawFileImage(); 


    public void run() { 

      Log.e("///enter ProcessData thread ","ProcessData thread"); 
     while(true){ 
     Bitmap image=Bitmap.createBitmap (320, 240, Bitmap.Config.RGB_565); 
        image.setPixels(pixelData,0,320 ,0 ,0,320,240); 
     message = handler.obtainMessage(1,obj); 
     handler.sendMessage(message); 
      } 

public Handler handler = new Handler(){ 


    @SuppressLint("NewApi") 
    @Override 
    public void handleMessage(Message msg) { 
      super.handleMessage(msg);   
      String MsgString = (String)msg.obj; 

      if (MsgString.equals("run")) 
      {    Log.e("///enter handler ","setImageBitmap");                         
          myImageView.setImageBitmap(image); 

      } 


    } 
}; 

logcat的

05-21 20:11:44.845: E/1(7267): 1 
    05-21 20:11:44.845: E/ProcessData thread(7267): ProcessData thread 
    05-21 20:11:44.845: E////enter handler(7267): setImageBitmap 
    05-21 20:11:44.855: D/dalvikvm(7267): GC_CONCURRENT freed 1K, 22% free 10613K/13575K, paused 12ms+2ms, total 34ms 
    05-21 20:11:44.855: D/dalvikvm(7267): WAIT_FOR_CONCURRENT_GC blocked 8ms 
    05-21 20:11:44.915: D/dalvikvm(7267): GC_CONCURRENT freed 895K, 25% free 10225K/13575K, paused 13ms+6ms, total 39ms 
    05-21 20:11:44.980: D/dalvikvm(7267): GC_CONCURRENT freed 439K, 25% free 10298K/13575K, paused 2ms+4ms, total 35ms 
    05-21 20:11:44.980: D/dalvikvm(7267): WAIT_FOR_CONCURRENT_GC blocked 22ms 
    05-21 20:11:45.030: D/dalvikvm(7267): GC_CONCURRENT freed 473K, 24% free 10337K/13575K, paused 1ms+4ms, total 26ms 
    05-21 20:11:45.030: D/dalvikvm(7267): WAIT_FOR_CONCURRENT_GC blocked 18ms 
    05-21 20:11:45.095: D/dalvikvm(7267): GC_CONCURRENT freed 467K, 24% free 10382K/13575K, paused 2ms+2ms, total 46ms 
    05-21 20:11:45.100: D/dalvikvm(7267): WAIT_FOR_CONCURRENT_GC blocked 41ms 
    05-21 20:11:45.185: D/dalvikvm(7267): GC_CONCURRENT freed 450K, 24% free 10443K/13575K, paused 12ms+5ms, total 55ms 
    05-21 20:11:45.185: D/dalvikvm(7267): WAIT_FOR_CONCURRENT_GC blocked 29ms 
    05-21 20:11:45.255: D/dalvikvm(7267): GC_CONCURRENT freed 469K, 23% free 10486K/13575K, paused 12ms+5ms, total 48ms 
    05-21 20:11:45.255: D/dalvikvm(7267): WAIT_FOR_CONCURRENT_GC blocked 27ms 
    05-21 20:11:45.320: D/dalvikvm(7267): GC_CONCURRENT freed 455K, 23% free 10542K/13575K, paused 12ms+5ms, total 48ms 
    05-21 20:11:45.320: D/dalvikvm(7267): WAIT_FOR_CONCURRENT_GC blocked 22ms 
    05-21 20:11:45.395: D/dalvikvm(7267): GC_CONCURRENT freed 448K, 22% free 10605K/13575K, paused 11ms+5ms, total 50ms 
    05-21 20:11:45.395: D/dalvikvm(7267): WAIT_FOR_CONCURRENT_GC blocked 25ms 

.. ...................

然後再次設置我的位圖!

,然後顯示出的那種10605K/13575K,暫停11毫秒+ 5ms的,總50ms的再次~~

+1

你是什麼意思,「效率不高」,究竟是什麼問題? –

+0

圖像必須改變得非常快! ,因爲它來自攝像機。 – DekangHu

+0

我的android設備中的圖像變化需要大約3秒鐘才能更改。 我想每1/30秒改變圖像。 – DekangHu

回答

1

ImageView沒有內置的視頻預覽。而且您也不會在實時應用程序中動態創建Bitmap

使用SurfaceView,TextureViewSurfaceTexture來渲染相機幀。