java - ImageObserver not working -



java - ImageObserver not working -

can tell me need imageobserver work. thought work. i'd print message when image loads doesn't... doing wrong? can answered easily.

import java.awt.graphics; import java.awt.image; import java.awt.image.bufferedimage; import java.awt.image.imageobserver; import java.io.file; import java.io.ioexception; import javax.imageio.imageio; import javax.swing.jframe; import javax.swing.jpanel; public class imagetest extends jpanel implements imageobserver { @override public boolean imageupdate(image img, int infoflags, int x, int y, int width, int height) { if((infoflags & allbits) == 0) { system.out.println("processing still"); homecoming true; } else { system.out.println("done processing"); homecoming false; } } public void paintcomponent(graphics g) { super.paintcomponent(g); g.drawimage(img, 0, 0, this); } bufferedimage img; public imagetest (){ seek { img = imageio.read(new file("res/soccer-ball.jpg")); } grab (ioexception e) { // todo auto-generated grab block e.printstacktrace(); } } public static void main(string args[]) { jframe f = new jframe(); f.setcontentpane(new imagetest()); f.setdefaultcloseoperation(jframe.exit_on_close); f.setsize(1000, 1000); f.setvisible(true); } }

instead of putting in drawimage utilize toolkit process image utilize instance of imageobserver prepare image

change this:

try { img = imageio.read(new file("res/soccer-ball.jpg")); } grab (ioexception e) { // todo auto-generated grab block e.printstacktrace(); }

to:

public class imagetest extends jpanel implements imageobserver { @override public boolean imageupdate(image img, int infoflags, int x, int y, int width, int height) { if((infoflags & allbits) == 0) { system.out.println("processing still"); homecoming true; } else { system.out.println("done processing"); repaint(); homecoming false; } } public void paintcomponent(graphics g) { super.paintcomponent(g); g.drawimage(img, 0, 0, this); } image img; public imagetest (){ toolkit toolkit = toolkit.getdefaulttoolkit(); img = toolkit.getimage("res/soccer-ball.jpg"); toolkit.prepareimage(img, -1, -1, this); } public static void main(string args[]) { jframe f = new jframe(); f.setcontentpane(new imagetest()); f.setdefaultcloseoperation(jframe.exit_on_close); f.setsize(1000, 1000); f.setvisible(true); } }

where need repaint jpanel when image finished processing or else image wont show.

java image

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -