-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
1.0
-
sparc
-
solaris_2.5
From: tmb
This does not look like form output to me.
Platform: Windows 95 or Linux/X11R6, JDK-1.0
The following program generates a white square for the rescaled image
that was generated by off-screen rescaling (see comments in "paint()")
when run as "java Bug2". Running it as "java Bug2 -" demonstrates
that all the other setup is working.
Thomas.
// drawImage with rescaling doesn't seem to work properly when the
// destination is an off-screen pixmap
import java.awt.*;
import java.awt.image.*;
import java.net.*;
import java.applet.*;
import java.util.Vector;
import java.lang.*;
import java.io.*;
import sun.awt.image.FileImageSource;
class Bug2 extends Canvas {
static double min(double x,double y) { if(x<y) return x; else return y; }
static Image createImageComplete(Component c,ImageProducer source) {
Image image = c.createImage(source);
Bug2Wait w = new Bug2Wait();
if(!c.prepareImage(image,w)) w.waitfor();
return image;
}
Image scale(Image timage) {
int nw = 50, nh = 50;
Image nimage = createImage(nw,nh);
Graphics ng = nimage.getGraphics();
Bug2Wait ws;
if(!no_rescale) {
ws = new Bug2Wait();
if(!ng.drawImage(timage,0,0,nw,nh,ws)) ws.waitfor();
} else {
D("no rescale");
ws = new Bug2Wait();
if(!ng.drawImage(timage,0,0,ws)) ws.waitfor();
}
return nimage;
}
Image image = null;
Image image2 = null;
int count = 1;
static boolean no_rescale;
public void paint(Graphics g) {
if(image==null) {
D("loading image");
image = createImageComplete(this,new FileImageSource("foo.jpg"));
D("rescaling");
image2 = scale(image);
D("done");
}
g.setColor(Color.darkGray);
g.fillRect(0,0,10000,10000);
g.drawImage(image,0,0,this); // this works--it draws the original image
g.drawImage(image2,400,0,this); // this doesn't work--it yields just a white square
g.drawImage(image,0,200,60,60,this); // this works and draws a rescaled image
g.setColor(Color.white);
g.drawString(""+count++,400,200);
}
public static void main(String args[]) {
no_rescale = args.length>0;
Frame f = new Frame("Test");
Bug2 c = new Bug2();
c.resize(800,400);
f.add("Center",c);
f.pack();
f.show();
}
static void D(String s) { System.out.println(s); }
}
class Bug2Wait implements ImageObserver {
boolean done = false;
int flags = 0;
// NB: this uses polling because of a bug in notifyAll()
public boolean imageUpdate(Image img,int infoflags,int x,int y,int width,int height) {
flags = flags|infoflags;
if((infoflags&ERROR)!=0) System.out.println("wait: ERROR");
if((infoflags&ABORT)!=0) System.out.println("wait: ABORT");
if((infoflags&(ABORT|ALLBITS|ERROR|FRAMEBITS))!=0) {
done = true;
return false;
}
return true;
}
public void waitfor() {
while(true) {
if(done) return;
U.sleep(200);
}
}
}
This does not look like form output to me.
Platform: Windows 95 or Linux/X11R6, JDK-1.0
The following program generates a white square for the rescaled image
that was generated by off-screen rescaling (see comments in "paint()")
when run as "java Bug2". Running it as "java Bug2 -" demonstrates
that all the other setup is working.
Thomas.
// drawImage with rescaling doesn't seem to work properly when the
// destination is an off-screen pixmap
import java.awt.*;
import java.awt.image.*;
import java.net.*;
import java.applet.*;
import java.util.Vector;
import java.lang.*;
import java.io.*;
import sun.awt.image.FileImageSource;
class Bug2 extends Canvas {
static double min(double x,double y) { if(x<y) return x; else return y; }
static Image createImageComplete(Component c,ImageProducer source) {
Image image = c.createImage(source);
Bug2Wait w = new Bug2Wait();
if(!c.prepareImage(image,w)) w.waitfor();
return image;
}
Image scale(Image timage) {
int nw = 50, nh = 50;
Image nimage = createImage(nw,nh);
Graphics ng = nimage.getGraphics();
Bug2Wait ws;
if(!no_rescale) {
ws = new Bug2Wait();
if(!ng.drawImage(timage,0,0,nw,nh,ws)) ws.waitfor();
} else {
D("no rescale");
ws = new Bug2Wait();
if(!ng.drawImage(timage,0,0,ws)) ws.waitfor();
}
return nimage;
}
Image image = null;
Image image2 = null;
int count = 1;
static boolean no_rescale;
public void paint(Graphics g) {
if(image==null) {
D("loading image");
image = createImageComplete(this,new FileImageSource("foo.jpg"));
D("rescaling");
image2 = scale(image);
D("done");
}
g.setColor(Color.darkGray);
g.fillRect(0,0,10000,10000);
g.drawImage(image,0,0,this); // this works--it draws the original image
g.drawImage(image2,400,0,this); // this doesn't work--it yields just a white square
g.drawImage(image,0,200,60,60,this); // this works and draws a rescaled image
g.setColor(Color.white);
g.drawString(""+count++,400,200);
}
public static void main(String args[]) {
no_rescale = args.length>0;
Frame f = new Frame("Test");
Bug2 c = new Bug2();
c.resize(800,400);
f.add("Center",c);
f.pack();
f.show();
}
static void D(String s) { System.out.println(s); }
}
class Bug2Wait implements ImageObserver {
boolean done = false;
int flags = 0;
// NB: this uses polling because of a bug in notifyAll()
public boolean imageUpdate(Image img,int infoflags,int x,int y,int width,int height) {
flags = flags|infoflags;
if((infoflags&ERROR)!=0) System.out.println("wait: ERROR");
if((infoflags&ABORT)!=0) System.out.println("wait: ABORT");
if((infoflags&(ABORT|ALLBITS|ERROR|FRAMEBITS))!=0) {
done = true;
return false;
}
return true;
}
public void waitfor() {
while(true) {
if(done) return;
U.sleep(200);
}
}
}