小编any*_*guy的帖子

通过片段着色器进行YUV到RGB的转换

我在Android中将相机预览从YUV格式转换为RGB时遇到了问题.转换的目的是应用一些效果.我尝试通过片段着色器进行转换,因为本机代码的转换很慢(大约14fps).我使用的参考文献是http://jyrom.tistory.com/m/post/view/id/187.我尝试将此代码移植到Android平台,但结果是黑绿色矩形.但是,我可以通过输出看到某种形式.你可以试着帮我解决这个问题吗?我相信这是一个很受欢迎的问题:将效果应用于相机预览.我还提供了一个测试项目的链接:https://dl.dropbox.com/u/12829395/application/FilterGL/FilterGL.zip.谢谢.
更新:
这是我的onPreviewFrame方法:

public void onPreviewFrame(byte[] data, Camera camera) {
    yBuffer.put(data);
    yBuffer.position(0);

    System.arraycopy(data, U_INDEX, uData, 0, LENGTH_4 * 2);
    uBuffer.put(uData);
    uBuffer.position(0);

    System.arraycopy(data, V_INDEX, vData, 0, LENGTH_4);
    vBuffer.put(vData);
    vBuffer.position(0);
}
Run Code Online (Sandbox Code Playgroud)

这是我在onDrawFrame方法中将字节数组绑定到OpenGL纹理的方法:

    GLES20.glUniform1i(yTexture, 1);
    GLES20.glTexImage2D(   GLES20.GL_TEXTURE_2D, 0, GLES20.GL_LUMINANCE,
            320, 240, 0, GLES20.GL_LUMINANCE, GLES20.GL_UNSIGNED_BYTE, yBuffer);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);

    GLES20.glUniform1i(uTexture, 2);
    GLES20.glTexImage2D(   GLES20.GL_TEXTURE_2D, 0, GLES20.GL_LUMINANCE,
            160, 120, 0, GLES20.GL_LUMINANCE, GLES20.GL_UNSIGNED_BYTE, uBuffer);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);

    GLES20.glUniform1i(vTexture, 3);
    GLES20.glTexImage2D(   GLES20.GL_TEXTURE_2D, …
Run Code Online (Sandbox Code Playgroud)

shader camera android opengl-es fragment-shader

8
推荐指数
2
解决办法
2万
查看次数

RemoteViews和setOnClickPendingIntent

我尝试编写我的第一个小部件应用程序,我遇到了问题.所以,我有2个箭头:切换到左边并切换到右边.对于他们两个我想使用单个服务,它根据箭头的方向更改我的主屏幕小部件的视图.为了区分箭头的方向,我将额外的数据添加到我使用的每个意图中.这是我的示例代码:

    
RemoteViews remoteViews =
     new RemoteViews(context.getPackageName(),
      R.layout.presentation_layout);

 Intent updateServiceIntent1 = new Intent(context, UpdateService.class);
 updateServiceIntent1.putExtra("com.mycompany.direction", 1);
 PendingIntent updateServicePendingIntent1 =
     PendingIntent.getService(context, 0, updateServiceIntent1,
      PendingIntent.FLAG_UPDATE_CURRENT);
 //Action when we touch left arrow
 remoteViews.setOnClickPendingIntent(R.id.left,
  updateServicePendingIntent1);

 Intent updateServiceIntent2 = new Intent(context, UpdateService.class);
 updateServiceIntent2.putExtra("com.mycompany.direction", 0);
 PendingIntent updateServicePendingIntent2 =
     PendingIntent.getService(context, 0, updateServiceIntent2,
      PendingIntent.FLAG_UPDATE_CURRENT);
 //Action when we touch right arrow
 remoteViews.setOnClickPendingIntent(R.id.right,
  updateServicePendingIntent2);

 ComponentName thisWidget =
     new ComponentName(context, HelperWidget.class);
 AppWidgetManager manager = AppWidgetManager.getInstance(context);
 manager.updateAppWidget(thisWidget, remoteViews);
Run Code Online (Sandbox Code Playgroud)

在服务中我做下一个:


@Override
    public void onStart(Intent intent, int startId) {

   Log.i(TAG, "direction " + intent.getIntExtra("com.mycompany.direction", -1) …
Run Code Online (Sandbox Code Playgroud)

android android-widget android-intent android-pendingintent

5
推荐指数
0
解决办法
8994
查看次数