Some weird behaviour of the Applet
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Albert_Leng
Posted On:   Thursday, December 13, 2001 06:44 PM

I've created an applet which uses Java2D to blur an image file (image0.jpg)and display it in the browser. I can compile it with no problem but when i run the applet using the browser. The following message appears in the bottom of the browser "Start: applet not initialised". If i try to open a new window from the browser(ie. select "Window" from File>New in the menu), the applet can load successfully. The following message appears in the Java Console: java.lang.IllegalArgumentException: Width (-1) and height (0) must be > 0 at java.awt.image.SampleModel. (Unknown Source) at java.awt.image.SinglePixelPackedSampleModel. (Unknown Source) at java.awt.image.Raster.createPackedRaster(Unknown Source   More>>

I've created an applet which uses Java2D to blur an image file (image0.jpg)and display it in the browser. I can compile it with no problem but when i run the applet using the browser. The following message appears in the bottom of the browser "Start: applet not initialised". If i try to open a new window from the browser(ie. select "Window" from File>New in the menu), the applet can load successfully. The following message appears in the Java Console:

			java.lang.IllegalArgumentException: Width (-1) and height (0) must be > 0
			
at java.awt.image.SampleModel. (Unknown Source)
at java.awt.image.SinglePixelPackedSampleModel. (Unknown Source)
at java.awt.image.Raster.createPackedRaster(Unknown Source)
at java.awt.image.Raster.createPackedRaster(Unknown Source)
at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source)
at java.awt.image.BufferedImage. (Unknown Source)
at Convolve2.init(Convolve2.java:22)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java.lang.IllegalArgumentException: Width (-1) and height (0) must be > 0
at java.awt.image.SampleModel. (Unknown Source)
at java.awt.image.SinglePixelPackedSampleModel. (Unknown Source)
at java.awt.image.Raster.createPackedRaster(Unknown Source)
at java.awt.image.Raster.createPackedRaster(Unknown Source)
at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source)
at java.awt.image.BufferedImage. (Unknown Source)
at Convolve2.init(Convolve2.java:22)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)


The following is my code. Please have a look and tell me what's wrong. Thanks a lot!

			
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;

public class Convolve2 extends JApplet{
float ninth = 1.0f/9.0f;
float[] blurKernel = {
1.5f,ninth,ninth,
1.5f,ninth,ninth,
ninth,ninth,1.5f,
};
private Image chassis;
private BufferedImage bChassis;

public void init(){
setBackground(Color.white);
//load the image
chassis = getImage(getDocumentBase(),"image0.jpg");
int iw = chassis.getWidth(this);
int ih = chassis.getHeight(this);
//create BufferedImage as the source for image processin
bChassis = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = bChassis.createGraphics();
g2d.drawImage(chassis,0,0,this);
}





public void paint(Graphics g){
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);

int w = bChassis.getWidth(this);
int h = bChassis.getHeight(this);
//create a BufferedImage as the destination for image processing
BufferedImage bChassis2 = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
//Instantiate the operation
ConvolveOp cop = new ConvolveOp(new Kernel(3, 3, blurKernel));
cop.filter(bChassis,bChassis2);
Insets insets = getInsets();
g2.drawImage(bChassis2,insets.left, insets.top, null);


}
}
   <<Less
About | Sitemap | Contact