?
Solved

Creating an Image of a invisible component

Posted on 2003-11-04
9
Medium Priority
?
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:bumpert
ID: 9681393
humm ok
0
 

Accepted Solution

by:
vitallis earned 500 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month8 days, 7 hours left to enroll

766 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