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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:27:38+00:00 2026-05-24T16:27:38+00:00

I have a BufferedImage displayed in a JFrame through my own class. I opted

  • 0

I have a BufferedImage displayed in a JFrame through my own class. I opted to display the BufferedImage using my own class so I can scale it. My paintComponent and update

public class MyBuffIm{
public void paintComponent(Graphics canvas) {
    if (bi == null) {
    } else {
        //bi, maxWidth, and maxHeight were passed to constructor
        canvas.drawImage(bi, 0, 0, maxWidth, maxHeight, null);
    }
}

public void update(Graphics canvas) {
    super.update(canvas);
    if(bi != null){
        //Got this from some tutorial in the net.
        //Done out of desperation :|
        paintComponent(bi.getGraphics());
    }
}
}

I overrode update since the docs are saying something like “If this component is not a lightweight component, the AWT calls the update method in response to a call to repaint”. I’m not exactly sure if my component is lightweight or not.

In any case, I have the following code in my Runnable (does not work as I expect it to):

BufferedImage p = SomeMyBuffIm.getBuffIm();
Vector<Point> randomPixels = getRandomPixels(500);
int limit = randomPixels.size()
for (i = 0; i < limit; i++) {
    Point rp = randomPixels.get(i)
    p.setRGB(rp.x, rp.y, Color.red.getRGB());
}
SomeMyBuffIm.repaint();
mainFrame.repaint(); //JFrame call to repaint

I’d like to think that, since I’m scaling my image, I just can’t discern the difference between the new and old images. But I’ve tried the largest values for getRandomPixels still to no effect. My test image, by the way, is just a white sheet so red pixels should stand out in it.

Anything wrong I’m doing?

  • 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-24T16:27:39+00:00Added an answer on May 24, 2026 at 4:27 pm

    I overrode update since the docs are saying something like “If this component is not a lightweight component, the AWT calls the update method in response to a call to repaint”. I’m not exactly sure if my component is lightweight or not.

    No you should NOT override update(). You would do that with AWT but not with Swing.

    If you update the BufferedImage then all you need to do is invoke repaint() on your instance of the MyBuffin class.

    If you need more help than post your SSCCE that demonstrates the problem.

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

Sidebar

Related Questions

I have managed to load in an image using: BufferedImage image = ImageIO.read(out); and
I have the following Java code: public static BufferedImage createImage(byte[] data, int width, int
Following the javadocs, I have tried to scale a BufferedImage without success here is
I have some problems with rotating images in Java using the AffineTransform class. I
I have a Problem: I'm rendering a BufferedImage in a JFrame. Then i add
I have a static class and inside that class images are loaded into BufferedImage
I have a BufferedImage with an IndexColorModel. I need to paint that image onto
I have a transparent BufferedImage created with the following code(not relevant how it is
I have a JInternalFrame painted with a BufferedImage and contained in the JDesktopPane of
The title says enough I think. I have a full quality BufferedImage and I

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.