imagegrabber.java

来自「JavaExplorer是一个独立于平台的浏览器」· Java 代码 · 共 129 行

JAVA
129
字号
/**  * File and FTP Explorer  * Copyright 2003  * BOESCH Vincent  *  * 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; if not, write to the Free Software  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.  */package javaexplorer.util;import javaexplorer.Launcher;import javaexplorer.io.reader.*;import javaexplorer.io.writer.*;import javaexplorer.model.XFile;import javaexplorer.ressource.MagicNumber;import javax.swing.ImageIcon;/** * Classe utilis閑 pour lire et 閏rire les images * <p>Title: JExp</p> * <p>Description: File, FTP Explorer</p> * <p>Copyright: 2003</p> * <p>Company: N/A</p> * @author BOESCH Vincent * @version 4.4 */public class ImageGrabber {    private static ImageGrabber _grabber = new ImageGrabber();    private Launcher _launcher = null;    private GIFWriter _gw = new GIFWriter();    private JPEGWriter _jw = new JPEGWriter();    /**     *  Constructeur objet ImageGrabber     */    public ImageGrabber() {    }    /**     *  Gets the grabber attribute of the ImageGrabber     *  class     *     *@return    The grabber value     */    public static ImageGrabber getGrabber() {        return _grabber;    }    /**     *  Gets the image attribute of the ImageGrabber     *  object     *     *@param  fileName  Description of the     *      Parameter     *@return           The image value     */    public ImageIcon getImage(XFile xfile) {        int type = MagicNumber.getImageType(xfile);        //On regarde si l'extension du fichier est BMP :        if (type == MagicNumber.BMP) {            return new ImageIcon(BMPReader.getImage(xfile.getLocalFile()), xfile.getName());        } else {            return new ImageIcon(xfile.getLocalFile().getAbsolutePath(), xfile.getName());        }           }    /**     *@param  img       Description of the     *      Parameter     *@param  fileName  Description of the     *      Parameter     *@return           Description of the     *      Return Value     */    public boolean putImage(ImageIcon img, String fileName) {        //Dans tous les cas, les fichiers GIF sont traites par le GIFWriter        //Jimi ne sait pas encode en gif        try {            int type = MagicNumber.getImageType(null, fileName);            switch (type) {            case MagicNumber.GIF:                _gw.writeImage(fileName, img);                break;            //Par d閒aut, on 閏rit en JPEG            case MagicNumber.JPG:default:                _jw.writeImage(fileName, img);                break;            }            return true;        } catch (Exception e) {            javaexplorer.util.Log.addError(e);            return false;        }    }    /**     *  Sets the launcher attribute of the     *  ImageGrabber object     *     *@param  launcher  The new launcher value     */    public void setLauncher(Launcher launcher) {        _launcher = launcher;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?