Solved

Creating an Image of a invisible component

Posted on 2003-11-04
9
189 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
ID: 9680287
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
ID: 9680329
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
ID: 9680481
AFAIK, that's the situation i'm afraid
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:bumpert
ID: 9681393
humm ok
0
 

Accepted Solution

by:
vitallis earned 125 total points
ID: 9707900
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
ID: 9708049
thx someone already answer me on the java forum, but i'll give you the points
0
 

Author Comment

by:bumpert
ID: 9708053
java sun forum, sorry :)
0
 
LVL 86

Expert Comment

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

Author Comment

by:bumpert
ID: 9714587
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

813 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

9 Experts available now in Live!

Get 1:1 Help Now