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 8958587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:14:53+00:00 2026-06-15T15:14:53+00:00

How do I flip an Screenshot image? I can’t find my problem anywhere else.

  • 0

How do I flip an Screenshot image? I can’t find my problem anywhere else.
Example code:

/*
*@param fileLoc //Location of fileoutput destination
*@param format  //"png"
*@param WIDTH   //Display.width();
*@param HEIGHT  //Display.height();
*/
private void getScreenImage(){
             int[] pixels = new int[WIDTH * HEIGHT];
             int bindex;
             // allocate space for RBG pixels
             ByteBuffer fb = ByteBuffer.allocateDirect(WIDTH * HEIGHT * 3);//.order(ByteOrder.nativeOrder());
             // grab a copy of the current frame contents as RGB

             glReadPixels(0, 0, WIDTH, HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, fb);

             BufferedImage image = new BufferedImage(WIDTH, HEIGHT,BufferedImage.TYPE_INT_RGB);
             // convert RGB data in ByteBuffer to integer array
             for (int i=0; i < pixels.length; i++) {
                 bindex = i * 3;
                 pixels[i] =
                     ((fb.get(bindex) << 16))  +
                     ((fb.get(bindex+1) << 8))  +
                     ((fb.get(bindex+2) << 0));
             }
             try {
                //Create a BufferedImage with the RGB pixels then save as PNG
                 image.setRGB(0, 0, WIDTH, HEIGHT, pixels, 0 , WIDTH);

                 ImageIO.write(image, format , fileLoc);
             }
             catch (Exception e) {
                 System.out.println("ScreenShot() exception: " +e);
             }
         }

Basically the code works for capturing the screen and storing at as “png” format.
But it output’s the image horizontally flipped, because glReadPixels();,
read from bottom-left to top-right.

So how do I flip the image horizontally before I ImageIO.write();?

Thanks in-front,
Rose.

  • 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-06-15T15:14:54+00:00Added an answer on June 15, 2026 at 3:14 pm

    E.G. of flipping an image horizontally using an AffineTransform.

    flipping an image horizontally

    import java.awt.*;
    import java.awt.geom.AffineTransform;
    import java.awt.image.BufferedImage;
    import javax.swing.*;
    
    public class Test001 {
    
        public static BufferedImage getFlippedImage(BufferedImage bi) {
            BufferedImage flipped = new BufferedImage(
                    bi.getWidth(),
                    bi.getHeight(),
                    bi.getType());
            AffineTransform tran = AffineTransform.getTranslateInstance(bi.getWidth(), 0);
            AffineTransform flip = AffineTransform.getScaleInstance(-1d, 1d);
            tran.concatenate(flip);
    
            Graphics2D g = flipped.createGraphics();
            g.setTransform(tran);
            g.drawImage(bi, 0, 0, null);
            g.dispose();
    
            return flipped;
        }
    
        Test001(BufferedImage bi) {
            JPanel gui = new JPanel(new GridLayout(1,2,2,2));
    
            gui.add(new JLabel(new ImageIcon(bi)));
            gui.add(new JLabel(new ImageIcon(getFlippedImage(bi))));
    
            JOptionPane.showMessageDialog(null, gui);
        }
    
        public static void main(String[] args) throws AWTException {
            final Robot robot = new Robot();
            Runnable r = new Runnable() {
    
                @Override
                public void run() {
                    final BufferedImage bi = robot.createScreenCapture(
                            new Rectangle(0, 360, 200, 100));
                    new Test001(bi);
                }
            };
            SwingUtilities.invokeLater(r);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To flip an image around the center i am using this piece of code:
I can flip my view by doing something like this: image.transform = CGAffineTransformMakeScale(-1, 1);
I want to flip an imageView (left/right), but I can not find a UIView
I want to flip image for button's background in xml. I've seen example how
How can I flip the modal below which has multiple divs? <div id=modal> <div
I'm trying to flip between two views. That's easy, the code is below, but
How can I flip an NSWindow so I can press a button, and the
Hi I have to flip a thumpnail image before merge it with another jpeg
How can I flip the coordinate system of an NSWindow? I know it has
I'm trying to flip/mirror an image as I paint it on an HTML canvas;

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.