2011-11-06 32 views
2

我只想問如何在imageview上顯示後續圖像。我一次只能繪製一張圖像。在顯示第一張圖像後,我需要的是拍攝第二張圖像(第二張圖像將在運行時顯示)並在DELAY後顯示。然後第三幀然後第四等等..使用setImageBitmap函數,我只能顯示一個圖像,當我嘗試它爲後續圖像我無法看到輸出。 我也嘗試過使用onDraw函數,但得到相同的結果。 因爲我在JNI界面中獲取圖像信息。所以我可以使用GLSurfaceview來顯示圖像。因爲我是Android新手。我從來沒有使用OpenGL,所以任何人都可以提供一些代碼來顯示後續的圖像,無論是使用GLsurfaceView或類視圖的onDraw方法。 的我使用的是如下的代碼...如何在運行時在ImageView上顯示圖像

class Display1 extends ImageView 
{ 
Bitmap bMapScaled; 
Bitmap bit; 
Canvas c=new Canvas(); 
private static Context mContext = null; 
private static final String TAG = "Example:Display"; 
public Display1(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    mContext=context; 
} 



    public void drawImage(byte[] data, int width, int height) 
    { 
     Log.d(TAG, "drawImage2 called"); 
     bit=BitmapFactory.decodeByteArray(data, 0, data.length); 
     bMapScaled = Bitmap.createScaledBitmap(bit, 150, 150, true); 
     c.drawBitmap(bMapScaled, 0, 0, null); 
     this.setImageBitmap(bMapScaled); 
    } 
// public native void drawImage(byte[] data, int width, int height); 
    static { 
     System.loadLibrary("itv"); 
    } 

}

請幫我解決這個問題

由於提前

回答

1

您可能需要使用處理實施延遲之間的一系列事件:

int page_resid = R.drawable.yourFirstImage; // put your first img here 
    final Handler handler = new Handler(); 
    Timer t = new Timer(); 
    t.schedule(new TimerTask() { 
     public void run() { 
      handler.post(new Runnable() { 
       public void run() { 
        if (page_resid <= R.drawable.tut8) { 
         image.setImageResource(page_resid); 
         page_resid++ 
        } else { 
         finish(); // finished this series of img 
        } 
         } 
        }); 
     } 
    }, k_DELAY_TIME_IN_MS); // put your delay time here 
+0

感謝您的迴應。但那不是我想要的。我無法將圖像存儲在繪圖中。當我運行應用程序時,我從JNI界面獲取圖像。我只想顯示該圖像並返回到JNI以獲取第二個圖像並顯示在該圖像視圖上。對於時間延遲,我已經完成了編碼,我只想在圖像在運行時顯示圖像時逐個顯示圖像。 – geeta

0

看一看這部動畫可繪...

http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html

這可以幫助你......

+0

不,我不能將圖像存儲在可繪製的。我在處理某些功能後,我正在運行時獲取圖像。告訴我另一種方式... – geeta

+0

你應該可以使用標準程序,設置新的圖像使用setImageBitMap,你可以發佈你嘗試過的代碼嗎? –

+0

我已經粘貼了代碼..這個drawImage函數定期從JNI接口獲取圖像顯示。但我無法看到輸出..現在請幫助我... – geeta

相關問題