如何在 android 中使用 glreadpixels——通常是零 [英] how to use glreadpixels with android -- usually get zeros

查看:47
本文介绍了如何在 android 中使用 glreadpixels——通常是零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检测光标下的 opengl 对象...我已阅读它被称为采摘.这是我的代码:

I'm trying to detect the opengl object under the cursor... I have read it referred to as picking. Here is my code:

public int makeBuffer(GL10 gl, int x, int y) {

    ByteBuffer PixelBuffer = ByteBuffer.allocateDirect(4);
    PixelBuffer.order(ByteOrder.nativeOrder());
    PixelBuffer.position(0);
    int mTemp = 0;
    gl.glReadPixels((int)x, (int) y, 1, 1, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, PixelBuffer);
    Log.e("Picking", " xy: x" + x + " y"+ y);
    byte b [] = new byte[4];
    PixelBuffer.get(b);
    Log.e("Picking", " rgba: r"+ PixelBuffer.get(0) + " g" + PixelBuffer.get(1) + " b" +
            PixelBuffer.get(2) + " a" + PixelBuffer.get(3));
    Log.e("Picking", " rgba: r"+ b[0] + " g" + b[1] + " b" +
            b[2] + " a" + b[3]);

    //mTemp = PixelBuffer.get(0);
    mTemp = b[0];

    Log.e("Picking", "result:" + mTemp );

    return mTemp;
}

看到上面的大部分代码都是 logcat 语句.我的代码打印r、g 和 b 在屏幕上归零.对于 alpha,它打印-1",即可转换为 255(无符号)作为完整 alpha".我正在尝试检测一个屏幕上给定 x/y 位置的颜色.我会很高兴有一个红色值介于 1 到 15 之间,因为那是应该在触摸之下.我希望如果我这样做完全错误我会得到全零,但我至少必须这样做部分正确,因为我正在获得阿尔法.我还在我的清单告诉手机我使用权限表面抛掷器"和读取帧缓冲区".不知道这些是不是线路正常.

See that most of the code above is logcat statements. My code prints zeros to the screen for r,g, and b. For alpha it prints '-1' which is translatable to 255 (unsigned) as 'full alpha'. I'm trying to detect a color on the screen at the given x/y position. I would be happy with a red value that's somewhere between 1 and 15, as that's the color that should be below the touch. I would expect that if I was doing it entirely wrong I would get all zeroes, but I must be doing it at least partially right, as I'm getting alpha. I have also included lines in my manifest that tell the phone that I use the permissions for the 'surface flinger' and the 'read frame buffer'. I don't know if these lines are working.

<uses-permission
android:name="android.permission.ACCESS_SURFACE_FLINGER" />
<uses-permission android:name="android.permission.READ_FRAME_BUFFER" /

任何帮助将不胜感激.

推荐答案

这些权限仅适用于签名应用.编译 Android ROM 时签名的应用程序.因此,它们对常规应用无能为力.

These permissions are only available for signature apps. Apps that were signed when the Android ROM was compiled. So they do nothing for regular apps.

android:name="android.permission.ACCESS_SURFACE_FLINGER"
android:name="android.permission.READ_FRAME_BUFFER" 

这篇关于如何在 android 中使用 glreadpixels——通常是零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆