Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JAI Graphics2D.drawImage

Status
Not open for further replies.

stefes007

Programmer
Apr 24, 2001
21
BE
Hi, i'm writing an application that paint a TiledImage: this tiledimage is a background image where i want tu set different smaller images ( logos ) at different places.
here is the beginning of my method paint:

public void paint(TiledImage ti, Positioner pos){
Graphics g = ti.getGraphics();
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
String dir = Options.getHomeDir() + File.separator + "images" + File.separator + "symbols" + File.separator;

boolean aa = g2.drawImage(Toolkit.getDefaultToolkit().getImage(dir + "hail64p.gif"),70, 70, null);

this line doesn't work ( nothing is showed on that place )and aa is always false ( which mean it isn't still loaded )

I'm sure g2 is ok, because when I try this:

g2.setColor(Color.blue);
g2.drawString("testing drawstring",20,20);

it works... I don't understand the problem with drawImage. I've seen ( here: ) that JAI has problems with gif with transparent background, so i made my gif with a non-transparent background, but it doesn't resolve my problems: i'm also sure that the Toolkit works, because i've seen it detect that my gif size ( 64*64). Does anyone knows when this bug will be repaired ?

Thanks in advance for your help !
 
up

please, read-it, tell me sugestions ... It's very important !
 
where do you call this paint method?

Remenber that if you want to update the contents of a component (in your case, update the image that is located in a determined swing/awt component) you must call your paint method from the event dispatching thread or from the component's paint method ( public void paint(graphics g);)

I sugest you to call your paint method from the component's paint method :
public void paint(graphics g){
super.paint(g) // to clear the background. If you don´t do
// this the image inside the component
// maybe won´t be painted correctly

...
paint(tiledImage, positioner);
...
}

and whenever you want to call your paint method you must call component's repaint() method.


 

Hi espanolito,

Thank you for you for your help.

I'm gonna try your method: for the moment, i've found another solution:

public void paint(TiledImage ti, Positioner pos){
Graphics g = ti.getGraphics();
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
String dir = Options.getHomeDir() + File.separator + "images" + File.separator + "symbols" + File.separator;

try {

ParameterBlock pb = new ParameterBlock();
ParameterBlock pb2 = (new ParameterBlock()).add(dir + "hail64p.gif");


PlanarImage img = JAI.create("fileload", pb2);

pb.addSource(img); // The source image
pb.add((float)1); // The xScale
pb.add((float)1); // The yScale

pb.add((float)1); // The x translation
pb.add((float)1); // The y translation

pb.add(new InterpolationBilinear()); // The interpolation

PlanarImage pi = (PlanarImage)JAI.create("scale", pb, null);

// Draw the buffer
ti.set(pi);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top