/************************************************************************** /* This class implements an image-viewer using buffered-images. /* /* Copyright (c) 2006 by Bernhard Bablok (mail@bablokb.de) /* /* This program is free software; you can redistribute it and/or modify /* it under the terms of the GNU General Public License as published /* by the Free Software Foundation; either version 2 of the License or /* (at your option) any later version. /* /* This program is distributed in the hope that it will be useful, but /* WITHOUT ANY WARRANTY; without even the implied warranty of /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /* GNU General Public License for more details. /* /* You should have received a copy of the GNU General Public License /* along with this program; see the file COPYING. If not, write to /* the Free Software Foundation Inc., 59 Temple Place - Suite 330, /* Boston, MA 02111-1307 USA /**************************************************************************/ import java.io.*; import java.util.*; import java.awt.*; import java.awt.image.*; import java.awt.event.*; import java.awt.geom.*; import javax.imageio.*; import javax.imageio.stream.*; import javax.swing.*; /** This class implements an image-viewer using buffered-images. @version $Revision: 1.7 $ @author $Author: bablokb $ */ public class ImageViewer2 extends ImageViewer { ////////////////////////////////////////////////////////////////////////////// /** Constructor. */ public ImageViewer2(String title, ImagePanel2 panel) { super(title,panel); JMenuBar menuBar = getJMenuBar(); addMenu(menuBar); } ////////////////////////////////////////////////////////////////////////////// /** Add menu for image-manipulation. */ private void addMenu(JMenuBar menuBar) { JMenu menu = new JMenu("Transformation"); menu.add(new JMenuItem(new AbstractAction("Scale") { public void actionPerformed(ActionEvent e) { BufferedImage srcImg = (BufferedImage) getImage(); setImage(scaleImage(srcImg,0.75)); }; })); menu.add(new JMenuItem(new AbstractAction("Sharpen") { public void actionPerformed(ActionEvent e) { BufferedImage srcImg = (BufferedImage) getImage(); setImage(sharpenImage(srcImg)); }; })); menuBar.add(menu); setJMenuBar(menuBar); } ////////////////////////////////////////////////////////////////////////////// /** Scale image. */ private BufferedImage scaleImage(BufferedImage srcImg,double scale) { AffineTransform atf = AffineTransform.getScaleInstance(scale,scale); AffineTransformOp ato = new AffineTransformOp(atf,AffineTransformOp.TYPE_BILINEAR); // BufferedImage destImg = ato.createCompatibleDestImage(srcImg,null); return ato.filter(srcImg,null); } ////////////////////////////////////////////////////////////////////////////// /** Sharpen current image. */ public BufferedImage sharpenImage(BufferedImage srcImg) { srcImg = scaleImage(srcImg,1.0); final float[] kernelMatrix = { 0.f, -1.f, 0.f, -1.f, 5.0f, -1.f, 0.f, -1.f, 0.f}; Kernel kernel = new Kernel(3,3,kernelMatrix); ConvolveOp co = new ConvolveOp(kernel,ConvolveOp.EDGE_NO_OP,null); return co.filter(srcImg,null); } ////////////////////////////////////////////////////////////////////////////// /** Set image-files. */ protected void setImages(String[] filenames) throws IOException { BufferedImage[] imgArray = new BufferedImage[filenames.length]; for (int i=0;i