加载位图并在ImageView中高效显示

时间:2013-05-21 12:18:37

标签: android bitmap uiimageview

我的程序是解码位图并显示它。

原始解码代码和显示代码在我的电脑上运行完美。

当我在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,暂停11ms + 5ms,再次总共50ms ~~

1 个答案:

答案 0 :(得分:1)

ImageView不适用于视频预览。并且您也不会在实时应用程序中即时创建Bitmap

使用SurfaceViewTextureViewSurfaceTexture来渲染相框。