Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7400601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:16:22+00:00 2026-05-29T04:16:22+00:00

I found this code. This is supposed to read framebuffer and save it as

  • 0

I found this code. This is supposed to read framebuffer and save it as a png file.

It’s giving the error:

eglCreateWindowSurface() can only be called with an instance 
of SurfaceView or SurfaceHolder at the moment, this will be fixed later.

Code:

    private EGL10 egl;
    private EGLDisplay display;
    private EGLConfig config; 
    private EGLSurface surface;
    private EGLContext eglContext;
    private GL11 gl;
    //private GL10 gl10;
    protected int width, height;
    Bitmap mSavedBM;

    public void Take(Context context)
    {
        Display display= ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();        
        int screenWidth = display.getWidth();
        int screenHeight = display.getHeight();     
        String SCREENSHOT_DIR = "/sdcard/screenshots";
        initGLFr(); //GlView initialized.
        savePixels( 0, 10, screenWidth, screenHeight, gl); //this gets the screen to the mSavedBM.
        saveBitmap(mSavedBM, SCREENSHOT_DIR, "capturedImage");
    }

    private void initGLFr()
    {
        egl = (EGL10) EGLContext.getEGL();
        display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
        int[] ver = new int[2];
        egl.eglInitialize(display, ver);
        int[] configSpec = {EGL10.EGL_NONE};
        EGLConfig[] configOut = new EGLConfig[1];
        int[] nConfig = new int[1];
        egl.eglChooseConfig(display, configSpec, configOut, 1, nConfig);
        config = configOut[0];
        eglContext = egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT, null);
        surface = egl.eglCreateWindowSurface(display, config, SurfaceHolder.SURFACE_TYPE_GPU, null);
        egl.eglMakeCurrent(display, surface, surface, eglContext);
        gl = (GL11) eglContext.getGL();
    }

    public void savePixels(int x, int y, int w, int h, GL10 gl)
    {
        if (gl == null)
        {
            return;         
        }
        synchronized (this)
        {
            if (mSavedBM != null) 
            {
                mSavedBM.recycle();
                mSavedBM = null;
            }
        }
        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++)
        {
            //OpenGLbitmap is incompatible with Android bitmap
            //and so, some corrections need to be done.
            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 sb = Bitmap.createBitmap(bt, w, h, Bitmap.Config.ARGB_8888);
        synchronized (this)
        {
            mSavedBM = sb;
        }
    } 

    static String saveBitmap(Bitmap bitmap, String dir, String baseName) 
    {
        try 
        {
            File sdcard = Environment.getExternalStorageDirectory();
            File pictureDir = new File(sdcard, dir);
            pictureDir.mkdirs();
            File f = null;
            for (int i = 1; i < 200; ++i)
            {
                String name = baseName + i + ".png";
                f = new File(pictureDir, name);
                if (!f.exists()) 
                {
                    break;
                }
            }
            if (!f.exists()) 
            {
                String name = f.getAbsolutePath();
                FileOutputStream fos = new FileOutputStream(name);
                bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
                fos.flush();
                fos.close();
                return name;
            }
        }
        catch (Exception e) {} 
        return null;
    }

}

QUESTION:

Does this code take screenshots at a time when my application is in background or if it only makes screenshots of my application?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:16:23+00:00Added an answer on May 29, 2026 at 4:16 am

    You can’t take screenshots (that would be a security vulnerability), only system apps can do it.
    This method will most likely save a black PNG.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i found this code: protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); HwndSource hwndSource =
I found this code using Google. private int RandomNumber(int min, int max) { Random
I found this code for alphanumeric check (Letters, numbers, spaces or underscores) but I
i found this code at activestate, it takes a string and prints permutations of
I found this code from here: http://www.cssportal.com/form-elements/text-box.htm But the problem is you can still
I found this code here class Usable; class Usable_lock { friend class Usable; private:
I found this via google: http://www.mvps.org/access/api/api0008.htm '******************** Code Start ************************** ' This code was
Here I found this code: import java.awt.*; import javax.swing.*; public class FunWithPanels extends JFrame
I just found this code in reflector in the .NET base libraries... if (this._PasswordStrengthRegularExpression
I have found this code for reverse geocoding: var point = new GLatLng (lat[1],long[1]);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.