Results 1 to 13 of 13
- 04-13-2011, 11:51 AM #1
Member
- Join Date
- Apr 2010
- Posts
- 8
- Rep Power
- 0
Java Applet loading image; render as you get image?
Hi all, I'm writing a very simple applet which fetches an image from an external URL (using java.net.URL) and paints the image in my applet. I succeeded in loading the image. However now I would like to enhance my applet so that it renders the image progressively as it it fetched from the URL (in a Firefox manner, rendering from top to bottom). I would greatly appreciate if anyone can help me with this issue. Thanks
- 04-13-2011, 01:36 PM #2
This is just a guess, but have you looked at ImageObserver yet? I wonder what happens if you override imageUpdate() and draw what you have of the image as that method is called?
Last edited by KevinWorkman; 04-13-2011 at 02:22 PM.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-13-2011, 02:10 PM #3
Member
- Join Date
- Apr 2010
- Posts
- 8
- Rep Power
- 0
Thanks for getting back to me Kevin, I looked into the ImageObserver and it might be a promising idea to use it in conjunction with repaint(). I'll also look into the ImageUpdate. Will report back. Thanks for the time being
- 04-13-2011, 03:42 PM #4
Member
- Join Date
- Apr 2010
- Posts
- 8
- Rep Power
- 0
I can't seem to figure exactly out how ImageObserver works and how can harness its functionality for my purpose. Can somebody kindly help me out? I'm at loss about this image loading issue, it seems rather impossible to get it done
- 04-14-2011, 10:39 AM #5
Member
- Join Date
- Apr 2010
- Posts
- 8
- Rep Power
- 0
I finally managed to figure out how to override the imageUpdate. I also learned that there is a system property, awt.image.incrementalDraw, which by default should be set to True and which enables the drawing of images in an incremental fashion. However mine was defaulted to false, so I had to manually enable it. However I still haven't seen the results I expected, drawImage seems to persist on drawing the image only when all picture bytes arrive. Here is my applet code so far:
Java Code:import java.applet.*; import java.awt.*; import java.awt.image.ImageObserver; import java.io.IOException; import java.net.URL; public class imageApp extends Applet { Image image; public void init () { System.setProperty("awt.image.incrementalDraw", "true"); incrementaldraw = Boolean.getBoolean("awt.image.incrementalDraw"); System.out.println(incrementaldraw); //Verify incrementalDraw is set to true try{ URL url = new URL("http://geoeyemediaportal.s3.amazonaws.com/gallery/Inauguration_2009.jpg"); image = getImage(url); } catch(IOException e){} } [INDENT][/INDENT]public void paint (Graphics g) { g.drawImage (image, 0, 0, this); } public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { if ((infoflags & SOMEBITS ) != 0){ repaint(); } return super.imageUpdate(img, infoflags, x, y, width, height); } }
- 04-14-2011, 01:17 PM #6
I don't think imageUpdate() is working how we (I) expected it to. I put a print statement in there, and it seems to never be called. Weird. I might be out of my depth on this one.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-14-2011, 01:30 PM #7
Crossposted: Incremental image drawing in Java
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-14-2011, 01:31 PM #8
Member
- Join Date
- Apr 2010
- Posts
- 8
- Rep Power
- 0
Do you mean something like this below ? If I put a System.out.println in that section it actually prints out, therefore repaint is being called. I think the problem derives from drawImage or the java Graphics component.
I also found this bug with older versions of jdk, but I assume it must have been fixed since then: Bug ID: 5034556 drawImage behaviorJava Code:public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { if ((infoflags & SOMEBITS ) != 0){ System.out.println ("REPAINTING!");//<------------------------ repaint(); } return super.imageUpdate(img, infoflags, x, y, width, height); }
I'm completely at a loss about this issue :confused:
- 04-14-2011, 01:40 PM #9
I meant something like this:
Actually, I wouldn't be surprised if that bug is unfixed. Which means this might not be doable. But maybe somebody smarter than me can swoop in and tell us what we're missing.Java Code:@Override public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { System.out.println("imageUpdate"); //if ((infoflags & SOMEBITS ) != 0){ repaint(); //} return super.imageUpdate(img, infoflags, x, y, width, height); }How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-14-2011, 01:44 PM #10
Yeah, here's the "main" bug report for this: Bug ID: 4098417 Component does not update image incrementally
It doesn't look like it, or any of its related bugs, has been fixed yet. There might be a workaround, but I wouldn't know what it is. Sorry. Hopefully somebody else can help more.How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-14-2011, 01:47 PM #11
Member
- Join Date
- Apr 2010
- Posts
- 8
- Rep Power
- 0
If I place at that location, System.out.println("imageUpdate"); get called as well. Doesn't seem to make a difference though. How someone else can give us a helping hand on this one. Thanks very much for the time being Kevin
- 04-14-2011, 01:53 PM #12
Interesting. I threw together this application version, hopefully somebody can use it to figure out a workaround:
Java Code:import java.awt.*; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.JFrame; import javax.swing.JPanel; public class ImageApp extends JPanel { Image image; public ImageApp () { System.setProperty("awt.image.incrementalDraw", "true"); boolean incrementaldraw = Boolean.getBoolean("awt.image.incrementalDraw"); System.out.println(incrementaldraw); //Verify incrementalDraw is set to true new Thread(){ public void run(){ try{ image = ImageIO.read(new File("C:/Documents and Settings/kworkman/Desktop/Inauguration_2009.jpg")); //image = ImageIO.read(new File("http://geoeyemediaportal.s3.amazonaws.com/gallery/Inauguration_2009.jpg")); } catch(IOException e){} } }.start(); } public void paintComponent(Graphics g) { super.paintComponent(g); //if(image != null){ g.drawImage (image, 0, 0, this); //} } @Override public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { System.out.println("imageUpdate"); //if ((infoflags & SOMEBITS ) != 0){ repaint(); //} return super.imageUpdate(img, infoflags, x, y, width, height); } public static void main(String... args){ JFrame frame = new JFrame("Image Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new ImageApp()); frame.setSize(500,500); frame.setVisible(true); } }How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-14-2011, 01:58 PM #13
Member
- Join Date
- Apr 2010
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
Java Applet Strange Image Loading Problem
By 1yuchen in forum Java AppletsReplies: 36Last Post: 01-06-2012, 02:06 AM -
Image Loading
By hobbles in forum New To JavaReplies: 10Last Post: 09-06-2010, 08:30 PM -
Loading image in applet
By syarizma in forum Advanced JavaReplies: 0Last Post: 08-06-2009, 09:02 AM -
loading image into applet
By balaram in forum Java AppletsReplies: 1Last Post: 11-06-2008, 02:13 PM -
Loading An Image Help Please!
By shaungoater in forum Java 2DReplies: 2Last Post: 01-09-2008, 08:14 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks