截图中的机器人 [英] screenshot in android

查看:116
本文介绍了截图中的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是code我使用采取了截屏使用GLSurfaceView。但我不知道为什么在GLSurfaceView.Renderer类的OnDraw()方法不会被调用。

The following is the code I am using to take a screen shot using GLSurfaceView. But I dont know why the onDraw() method in the GLSurfaceView.Renderer Class is not being called.

请,如果一些人可以看看下面的code,并指出我在做什么wrong.`public类MainActivity延伸活动{

Please if some one can look at the code below and point out what am I doing wrong.`public class MainActivity extends Activity {

private GLSurfaceView mGLView;
int x,y,w,h;
Display disp;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    // ToDo add your GUI initialization code here

    setContentView(R.layout.main);
    x=0;
    y=0;

    disp = getWindowManager().getDefaultDisplay();

    w = disp.getWidth();
    h = disp.getHeight();

   mGLView = new ClearGLSurfaceView(this);


}

class ClearGLSurfaceView extends GLSurfaceView {
public ClearGLSurfaceView(Context context) {
    super(context);
    setDebugFlags(DEBUG_CHECK_GL_ERROR | DEBUG_LOG_GL_CALLS);
    mRenderer = new ClearRenderer();
    setRenderer(mRenderer);
}

    ClearRenderer mRenderer;

}

class ClearRenderer implements GLSurfaceView.Renderer {

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    // Do nothing special.
}

public void onSurfaceChanged(GL10 gl, int w, int h) {
    //gl.glViewport(0, 0, w, h);
}

public void onDrawFrame(GL10 gl) {
    //gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    int b[]=new int[w*(y+h)];

     int bt[]=new int[w*h];

     IntBuffer ib=IntBuffer.wrap(b);

     ib.position(0);

     gl.glReadPixels(x, 0, w, y+h, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, ib);



     for(int i=0, k=0; i<h; i++, k++)

     {//remember, that OpenGL bitmap is incompatible with Android bitmap

      //and so, some correction need.

          for(int j=0; j<w; j++)

          {

               int pix=b[i*w+j];

               int pb=(pix>>16)&0xff;

               int pr=(pix<<16)&0x00ff0000;

               int pix1=(pix&0xff00ff00) | pr | pb;

               bt[(h-k-1)*w+j]=pix1;

          }

     }




     Bitmap bmp = Bitmap.createBitmap(bt, w, h,Bitmap.Config.ARGB_8888);

     try

            {
                    File f = new File("/sdcard/testpicture.png");
                    f.createNewFile();
                    FileOutputStream fos=new FileOutputStream(f);

                    bmp.compress(CompressFormat.PNG, 100, fos);

                    try

                    {

                            fos.flush();

                    }

                    catch (IOException e)

                    {

                            // TODO Auto-generated catch block

                            e.printStackTrace();

                    }

                    try

                    {

                            fos.close();

                    }

                    catch (IOException e)

                    {

                            // TODO Auto-generated catch block

                            e.printStackTrace();

                    }



            }

            catch (FileNotFoundException e)

            {

                    // TODO Auto-generated catch block

                    e.printStackTrace();

            }
            catch(IOException e)
            {
                e.printStackTrace();
            }

}

}

}

`

请人帮助我。 我刚开始学习工作的机器人。

Please someone help me out. I have just started learning to work on android.

推荐答案

尽管创建surfaceview,你不将它设置为当前内容查看

Although you create the surfaceview, you don't set it to be the current contentview

setContentView(mGLView);

另外,你所创建的屏幕截图的每一个帧,这是非常低效的,可能不是你想要的。

Also, you are creating the screenshot every single frame, which is very inefficient and probably not what you'll want..

这篇关于截图中的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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