Solved

Creating an Image of a invisible component

Posted on 2003-11-04
9
187 Views
Last Modified: 2010-03-31
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
Comment
Question by:bumpert
  • 5
  • 3
9 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
You could only save an image of something when it's visible, so you'd have to show it then hide it.
0
 

Author Comment

by:bumpert
Comment Utility
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
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
AFAIK, that's the situation i'm afraid
0
 

Author Comment

by:bumpert
Comment Utility
humm ok
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Accepted Solution

by:
vitallis earned 125 total points
Comment Utility
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
 

Author Comment

by:bumpert
Comment Utility
thx someone already answer me on the java forum, but i'll give you the points
0
 

Author Comment

by:bumpert
Comment Utility
java sun forum, sorry :)
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Sorry bumpert - for some reason, an off-screen image didn't occur to me.
0
 

Author Comment

by:bumpert
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now