- Joined
- Mar 21, 2010
- Messages
- 4
- Reaction score
- 0
Hi people,
I was wondering if i could get some help with a problem I've run into? I have created a project in Netbeans which gets a JPEG file from my directory using JFilechooser. The image is displayed on a JLabel as an ImageIcon...
Now i want to blur the image and ive tried modifying the following code...
but i cant get anywhere. Can someone please point me in the right direction as to how/where I load the image?
I was wondering if i could get some help with a problem I've run into? I have created a project in Netbeans which gets a JPEG file from my directory using JFilechooser. The image is displayed on a JLabel as an ImageIcon...
Code:
private void import_standby_ButActionPerformed(java.awt.event.ActionEvent evt) {
fc.setCurrentDirectory(new File("user.dir"));
fc.setAcceptAllFileFilterUsed (false);
FileNameExtensionFilter filter = new FileNameExtensionFilter("JPG Images", "jpg");
fc.setFileFilter(filter);
fc.setAccessory(new ImagePreview(fc));
int result = fc.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION) {
File selectedFile = fc.getSelectedFile();
System.out.println(selectedFile.getParent());
File file = fc.getSelectedFile();
System.out.println(selectedFile.getName());
// Read image and place new file icon into preferred locations
BufferedImage newImage = null;
try {
newImage = ImageIO.read(file);
} catch(IOException e) {
System.out.println("read error: " + e.getMessage());
}
ImageIcon backgdIcon = new ImageIcon(newImage);
stadbyImgLabel.setIcon(backgdIcon);
// Enables Remove Button
standby_remove_But.setEnabled(true);
} else if (result == JFileChooser.CANCEL_OPTION) {
System.out.println(JFileChooser.CANCEL_OPTION);
}
}
Now i want to blur the image and ive tried modifying the following code...
Code:
Image displayImage;
BufferedImage biSrc;
BufferedImage biDest; // Destination image is mandetory.
BufferedImage bi; // Only an additional reference.
Graphics2D big;
CPanel() {
setBackground(Color.black);
loadImage();
setSize(displayImage.getWidth(this), displayImage.getWidth(this));
createBufferedImages();
bi = biSrc;
}
public void loadImage() {
displayImage = Toolkit.getDefaultToolkit().getImage("displayImage.jpg");// is this correct???
MediaTracker mt = new MediaTracker(this);
mt.addImage(displayImage, 1);
try {
mt.waitForAll();
} catch (Exception e) {
System.out.println("Exception while loading.");
}
if (displayImage.getWidth(this) == -1) {
System.out.println("No jpg file");
System.exit(0);
}
}
public void createBufferedImages() {
biSrc = new BufferedImage(displayImage.getWidth(this), displayImage
.getHeight(this), BufferedImage.TYPE_INT_RGB);
big = biSrc.createGraphics();
big.drawImage(displayImage, 0, 0, this);
biDest = new BufferedImage(displayImage.getWidth(this), displayImage
.getHeight(this), BufferedImage.TYPE_INT_RGB);
}
public void blur() {
float data[] = { 0.0625f, 0.125f, 0.0625f, 0.125f, 0.25f, 0.125f,
0.0625f, 0.125f, 0.0625f };
Kernel kernel = new Kernel(3, 3, data);
ConvolveOp convolve = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP,
null);
convolve.filter(biSrc, biDest);
bi = biDest;
}
but i cant get anywhere. Can someone please point me in the right direction as to how/where I load the image?