2011-01-08 6 views
3

다음은 GLSurfaceView를 사용하여 스크린 샷을 찍는 데 사용하는 코드입니다. 하지만 GLSurfaceView.Renderer 클래스의 onDraw() 메서드가 호출되지 않는 이유는 모르겠습니다.android

일부 코드가 아래 코드를 살펴보고 내가 뭘 잘못하고 있는지 지적하십시오.

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(); 
       } 

    } 
} 

} 

나를 도와주세요. 나는 안드로이드에 대해 배우기 시작했습니다.

+1

OpenGL ES 1.0, 1.1 또는 2.0? – Kos

답변

1

당신은 서피스 뷰 SurfaceView를 만들 수 있지만, 현재 내용 없음 또한

setContentView(mGLView); 

, 당신은 매우 비효율적이고 아마하지 않은 스크린 샷마다 하나의 프레임을 만드는에게로 설정하지 않는 당신이거야 원하는 ..

+0

감사합니다. 하지만 나는 며칠 전에 그것을 알아 냈다. 한 가지 더 공유하고 싶은 점은 전체 화면의 스크린 샷을 찍고 싶다는 것입니다. 이 메서드는 뷰의 스크린 샷만을 가져옵니다. 그래서이 방법은 도움이되지 않습니다. 또한 며칠 동안 그물을 탐색 한 결과, 전체 화면의 스크린 샷을 찍을 때 필연적으로 전화를 뿌리 뽑을 필요가 있다고 결론지었습니다. 전화를 뿌리 뽑을 필요가없이 작업을 수행 할 수있는 것을 제안 할 수 있다면, 고맙습니다. – ujjawal

관련 문제