[java] graphics2D

Started by
6 comments, last by himifire 20 years, 6 months ago
im using the code..... g2d.setTransform(new AffineTransform()); g2d.drawImage(images, new AffineTransform(), b); to try n draw an image. the image is already loaded i check it wit mediaTracker. b is a component. i is the for loop variable. help im gettin nothing!! What am i doing wrong!! i just switched from graphics to graphics2D so i dont really understand AffineTransform yet. it might be the problem.... :<( :<( :<( :<(
___________________________________________________________ DADDY LONG LEGZ HERE! novice java programmer :-)feel free to email me or my SN for AIM is JHHIM
Advertisement
MediaTracker will return even if the image is not loaded. Even using MediaTracker.waitForAll() will return before all the images are loaded. The best way to wait is to use MediaTracker.checkAll() and then Thread.sleep for a few Millis.
sorry for the lack of info but i already used waitForID(thierid)
i think it must be something in the
g2d.drawImage(images, new AffineTransform(), b);
line.
heres the rest of the code

import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
class bufferTest extends Component
{
public static void main(String[] args)
{
bufferTest b = new bufferTest();
Image strip = Toolkit.getDefaultToolkit().getImage("cloverStrip.gif");
MediaTracker mt = new MediaTracker(b);
mt.addImage(strip, 1);

try{
mt.waitForID(1);
}
catch(Exception e) {
System.out.println("ERROR ERROR");
}

JFrame frame = new JFrame();
frame.setBounds(300,300,200, 200);
frame.setResizable(false);
frame.setVisible(true);
Graphics2D g2d =(Graphics2D) frame.getGraphics();


Image[] images = destriper.deStrip(70, 94, 2, b, strip, 13);


for(int x = 0; x < images.length; x++)
{
mt.addImage(images[x], 0);
}

try{
mt.waitForID(0);
}
catch(Exception e) {}




for(int i = 0; i < 13; i++)
{
g2d.setTransform(new AffineTransform());
g2d.drawImage(images, new AffineTransform(), b);

try{
Thread.sleep(1000);;
System.out.println("!");
}
catch(Exception e) {;}

}
}


}

there might be more code than needed cause i tried to find the problem. the destiper.deStrip method takes an image and breaks it up returning an image array.
___________________________________________________________ DADDY LONG LEGZ HERE! novice java programmer :-)feel free to email me or my SN for AIM is JHHIM
Try putting ''[''code'']'' and ''[''/code'']'' around your code without the tick marks, it makes it more readable.

There is no function drawImage that takes an image array as an argument. Do you even know if destrip is returning a non NULL array?

I would suggest backing out of all this code; go back and do one thing at a time until you understand why it works the way it does and then add the next part because your code has alot of problems. Like for example why are you adding the images from the image array to the MediaTracker? And why are you creating two new AffineTransforms?
If you''re using Graphics2D and AffineTransform, you''ve then ditched Java 1.1 and moved into Java 2 and Java 2D. In that case, use the new stuff!! ImageIO instead of Toolkit, BufferedImage instead of Image, no need to bother with trackers at all. The new stuff is higher performance, easier to use, blocks*, and is just plain better. Read up some tutorials on java 2D, or better yet get the book "Java 2D Graphics" (wow do I recommend that a lot around here...)

*as in calls to load/create BufferedImages won''t return until they are done. Unless an error occurs, a BufferedImage is always a full, complete image. There''s no guess work.

(...I still don''t understand why so many people think they can just "figure this stuff out". Java 2D and Java''s graphics systems in general are very big and complex...)
quote:Original post by nonnus29
MediaTracker will return even if the image is not loaded. Even using MediaTracker.waitForAll() will return before all the images are loaded. The best way to wait is to use MediaTracker.checkAll() and then Thread.sleep for a few Millis.


You are mistaken. waitForAll() will wait for all images to load, unless there is an error.

quote:From the API docs:
Starts loading all images tracked by this media tracker. This method waits until all the images being tracked have finished loading.
If there is an error while loading or scaling an image, then that image is considered to have finished loading. Use the isErrorAny or isErrorID methods to check for errors.



First make it work,
then make it fast.

--Brian Kernighan

The problems of this world cannot possibly be solved by skeptics or cynics whose horizons are limited by the obvious realities. We need men and women who can dream of things that never were. - John Fitzgerald Kennedy(35th US President)

Do not interrupt your enemy when he is making a mistake. - Napolean Bonaparte
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
quote:Original post by CaptainJester
quote:Original post by nonnus29
MediaTracker will return even if the image is not loaded. Even using MediaTracker.waitForAll() will return before all the images are loaded. The best way to wait is to use MediaTracker.checkAll() and then Thread.sleep for a few Millis.


You are mistaken. waitForAll() will wait for all images to load, unless there is an error.




I guess its the blocking/nonblocking thing that makes it seem that way?
thx guys i got it to work. all the unneeded code i put there cuz i was tryin to find the problem. i prob should have posted the original. ={ my bad. ill try to up my java skills to java 2 but im only a beginner 13-year old so i think its an acomplishment to get this far!!
___________________________________________________________ DADDY LONG LEGZ HERE! novice java programmer :-)feel free to email me or my SN for AIM is JHHIM

This topic is closed to new replies.

Advertisement