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

  • SEARCH
  • Home
  • 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 6990977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:25:49+00:00 2026-05-27T19:25:49+00:00

I am using the following code. The image is saved but it is BLACK.

  • 0

I am using the following code. The image is saved but it is BLACK.
Please see my code and tell me where I am doing wrong.
I am using this code in the Menu.

case R.id.id_menu_Save:

            Bitmap bmp = SavePixels(0, 0, 800, 400, CCDirector.sharedDirector().gl);

            File file = new File("/sdcard/test.jpg");
            try
            {
                file.createNewFile();
                FileOutputStream fos = new FileOutputStream(file);
                bmp.compress(CompressFormat.JPEG, 100, fos);

                Toast.makeText(getApplicationContext(), "Image Saved", 0).show();
                Log.i("Menu Save Button", "Image saved as JPEG");
            }

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

            break;

This is my Save Image Function.

public static Bitmap SavePixels(int x, int y, int w, int h, GL10 gl)
{  
     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 sb = Bitmap.createBitmap(bt, w, h, Bitmap.Config.ARGB_8888); 
    return sb;
}

Apart from above, what I want from you is to point me in the right direction. Like if I have to get the pixels of the screen, what class/entity should I be exploring?

  • 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-27T19:25:50+00:00Added an answer on May 27, 2026 at 7:25 pm

    Just change SavePixelx method to the below:

    public static Bitmap SavePixels(int x, int y, int w, int h, GL10 gl)
    {  
         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)&0xffff0000;
                   int pix1=(pix&0xff00ff00) | pr | pb;
                   bt[(h-k-1)*w+j]=pix1;
              }
         }
    
        Bitmap sb = Bitmap.createBitmap(bt, w, h, Bitmap.Config.ARGB_8888); 
        return sb;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using following code but cannot return data from MySQL. This is the output:
I have saved an image in database using following code. ofd.ShowDialog() vrPicHolder = IO.File.ReadAllBytes(ofd.FileName)
I am using the following code to draw text onto a jpg image but
I am creating several image dynamically using the following code: function refresh_gallery(galleryidentifier, albumid) {
Well I am using the following code to take any old image into a
Hi there im using the following code for insert text and images, but I
I am converting Base64 code to image and I am using following way to
I'm creating a thumbnail for an image using the following code: im = Image.open('original.jpg')
Consider this code for loading, modifying and saving a Bitmap image: using (Bitmap bmp
I have the following code. QString fileName = QFileDialog::getSaveFileName( this, tr(Output Image file), (),

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.