2010-07-20 74 views
1

我有2班GLLayerGLCamTest。我試圖運行位於GLCamTest的方法...我如何在這裏實現一個處理程序?

 public Bitmap extractimage(int pos){ 
    LocationData tweets; 
    tweets = new LocationData(this); 
    SQLiteDatabase db = tweets.getWritableDatabase(); 
    //select the data 
    String query = "SELECT * FROM tweets;"; 
    Cursor mcursor = db.rawQuery(query, null); 
    //Move to Position specified. 
    mcursor.moveToPosition(pos); 

    //get it as a ByteArray 
    byte[] imageByteArray=mcursor.getBlob(7); 
    //the cursor is not needed anymore 
    mcursor.close(); 

    //convert it back to an image 
    ByteArrayInputStream imageStream = new ByteArrayInputStream(imageByteArray); 
    Bitmap theImage = BitmapFactory.decodeStream(imageStream); 
    return theImage; 
    } 

我期待從GLLayer,但是從我的理解,我需要一個處理器上的線程來運行..

  public void run() { 
    GLCamTest cam = new GLCamTest(); 
    image = cam.extractimage(q); 

} 

我從public void onDrawFrame(GL10 gl) {開始線程我的問題是我將如何實現上述處理程序?我讀過http://developer.android.com/reference/android/os/Handler.html,但我仍然不太明白我將如何實施它。有人能幫助我嗎?

回答

1

兩件事。一個是GLThread永遠不會調用Looper.prepare(),因此你不能在該線程中添加/創建一個處理程序。 (應該在主UI線程內)。

二,不需要處理程序。如果你只是想渲染線程中執行代碼...

GLSurfaceView mySurface = mMyCustomSurfaceIMadeEarlierWithTheRendererAlreadyAttached; 
Runnable myRunnable = mMyRunnableThatIsSomewhere; 
mySurface.queueEvent(myRunnable); 

了Runnable將渲染線程內之前並條機方法被調用的下一個渲染通道被執行。

相關問題