我将如何在这里实现处理程序?
我有 2 个类 GLLayer
和 GLCamTest
。我正在尝试运行位于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有两件事。一是 GLThread 从未调用过 Looper.prepare(),因此您无法在该线程内添加/创建处理程序。 (应该在主 UI 线程内)。
第二,不需要处理程序。如果您只想在渲染线程内执行代码...
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...
The runnable will be executed inside your render thread before the drawFrame method gets called on the next rendering pass.