• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 199
  • Last Modified:

Creating an Image of a invisible component

Hi, i know how to create a Image from a JComponent or anything that have a paint function. It create my Image with no problem. But now i have to create a Image Object of a JComponent that the user won't have to see. I set my Component to setVisible(false) and when i create the Image, my Image Object is null but if i setVisible(true) and i do the Image it's ok. So my question: "is there a way to create an Image Object from a Component that are not visible?"

i use this code to create the Image Object


Rectangle rect = table.getBounds();
Image ima = createImage(rect.width, rect.height);
Graphics2D g = (Graphics2D) ima.getGraphics();
table.paint(g);
g.dispose();



thx
0
bumpert
Asked:
bumpert
  • 5
  • 3
1 Solution
 
CEHJCommented:
You could only save an image of something when it's visible, so you'd have to show it then hide it.
0
 
bumpertAuthor Commented:
hummm it's not really usefull.... cause i do my picture when a bi things is loading, so the user have the time to see the component visible, and i cant do my image elsewhere...

i was thinking that somebody could have a solution for that :(

thx
0
 
CEHJCommented:
AFAIK, that's the situation i'm afraid
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
bumpertAuthor Commented:
humm ok
0
 
vitallisCommented:
I had the same task and the solution was very simple. What I did is
- created offscreen buffered image
    int width = <desired width>;
    int height = <desired height>;
    java.awt.image.BufferedImage bi = new java.awt.image.BufferedImage(width, height, java.awt.image.TYPE_INT_ARGB);
- created Graphics2D of it
    java.awt.Graphics2D gr = ni.createGraphics();
- called the component paint()
    table.paint(gr);

Now I have an offscreen image.
0
 
bumpertAuthor Commented:
thx someone already answer me on the java forum, but i'll give you the points
0
 
bumpertAuthor Commented:
java sun forum, sorry :)
0
 
CEHJCommented:
Sorry bumpert - for some reason, an off-screen image didn't occur to me.
0
 
bumpertAuthor Commented:
no problem man, we cannot know all the things :)
if yes i didn't post qa question here :)

thx to all for your help
im leaving this topic
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now