我将如何在这里实现处理程序?

发布于 2024-09-10 11:18:49 字数 1250 浏览 0 评论 0原文

我有 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 onDrawFrame(GL10 gl) { 中启动线程,

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

}

我的问题是如何实现所述处理程序?我读过 http://developer.android.com/reference/android/ os/Handler.html 但我仍然不太明白如何实现它。有人可以帮我吗?

I've got 2 classes GLLayer and GLCamTest. I'm attempting to run a method located in 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;
    }

I'm looking to run in on a thread from GLLayer but from what I understand I need a Handler..

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

}

I'm starting the Thread from within public void onDrawFrame(GL10 gl) { my question is how would I implement said handler? I've read http://developer.android.com/reference/android/os/Handler.html but I still don't really understand how I'd implement it. could someone help me out?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪漫之都 2024-09-17 11:18:49

有两件事。一是 GLThread 从未调用过 Looper.prepare(),因此您无法在该线程内添加/创建处理程序。 (应该在主 UI 线程内)。

第二,不需要处理程序。如果您只想在渲染线程内执行代码...

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

runnable 将在下一个渲染过程中调用 drawFrame 方法之前在渲染线程内执行。

Two things. One is that the GLThread never called Looper.prepare() therefore you can't add/create a handler inside that thread. (Should be inside the main UI thread).

Two, a handler isn't needed. If you just want to execute code inside the render thread...

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

The runnable will be executed inside your render thread before the drawFrame method gets called on the next rendering pass.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文