亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? imageutil.java

?? java servlet著名論壇源代碼
?? JAVA
?? 第 1 頁(yè) / 共 2 頁(yè)
字號(hào):
/*
 * $Header: /cvsroot/mvnforum/myvietnam/src/net/myvietnam/mvncore/util/ImageUtil.java,v 1.12 2004/06/01 13:00:03 skoehler Exp $
 * $Author: skoehler $
 * $Revision: 1.12 $
 * $Date: 2004/06/01 13:00:03 $
 *
 * ====================================================================
 *
 * Copyright (C) 2002-2004 by MyVietnam.net
 *
 * 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 any later version.
 *
 * All copyright notices regarding MyVietnam and MyVietnam CoreLib
 * MUST remain intact in the scripts and source code.
 *
 * 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.
 *
 * Correspondence and Marketing Questions can be sent to:
 * info@MyVietnam.net
 *
 * @author: Minh Nguyen  minhnn@MyVietnam.net
 * @author: Mai  Nguyen  mai.nh@MyVietnam.net
 */
package net.myvietnam.mvncore.util;

import java.io.*;
import java.awt.image.BufferedImage;
import java.awt.geom.AffineTransform;
import java.awt.*;
import java.awt.image.*;
import javax.swing.ImageIcon;
import com.sun.image.codec.jpeg.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import net.myvietnam.mvncore.thirdparty.JpegEncoder;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.util.FileUtil;

public final class ImageUtil {

    private static Log log = LogFactory.getLog(ImageUtil.class);

    private ImageUtil() {// prevent instantiation
    }

    /**
     * @todo: xem lai ham nay, neu kich thuoc nho hon max thi ta luu truc tiep
     *          inputStream xuong thumbnailFile luon
     *
     * This method create a thumbnail and reserve the ratio of the output image
     * NOTE: This method closes the inputStream after it have done its work.
     *
     * @param inputStream     the stream of a jpeg file
     * @param thumbnailFile   the output file, must have the ".jpg" extension
     * @param maxWidth        the maximun width of the image
     * @param maxHeight       the maximun height of the image
     * @throws IOException
     * @throws BadInputException
     * @throws AssertionException
     */
    public static void createThumbnail(InputStream inputStream, String thumbnailFile, int maxWidth, int maxHeight)
        throws IOException, BadInputException, AssertionException {
        //boolean useSun = false;
        String lowerName = thumbnailFile.toLowerCase();
        if (!lowerName.endsWith(".jpg")) throw new BadInputException("Cannot create a thumbnail with the extension other than '.jpg'.");

        OutputStream outputStream = null;
        try {
            //JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(inputStream);
            //BufferedImage srcImage = decoder.decodeAsBufferedImage();
            byte[] srcByte = FileUtil.getBytes(inputStream);
            ImageIcon imageIcon = new ImageIcon(srcByte);
            Image srcImage = imageIcon.getImage();

            int imgWidth  = srcImage.getWidth(null);
            int imgHeight = srcImage.getHeight(null);
            //log.trace("width = " + imgWidth + " height = " + imgHeight);
            if ( (imgWidth <= 0) || (imgHeight <= 0) ) {
                // imgWidth or imgHeight could be -1, which is considered as an assertion
                throw new AssertionException("Assertion: ImageUtil: cannot get the image size.");
            }

            // Set the scale.
            AffineTransform tx = new AffineTransform();
            if ((imgWidth > maxWidth) || (imgHeight > maxHeight)) {
                double scaleX = (double)maxWidth/imgWidth;
                double scaleY = (double)maxHeight/imgHeight;
                double scaleRatio = (scaleX < scaleY) ? scaleX : scaleY;
                imgWidth  = (int)(imgWidth  * scaleRatio);
                imgHeight = (int)(imgHeight * scaleRatio);
                // scale as needed
                tx.scale(scaleRatio, scaleRatio);
            } else {// we dont need any transform here, just save it to file and return
                outputStream = new FileOutputStream(thumbnailFile);
                outputStream.write(srcByte);
                return;
            }

            // create thumbnail image
            BufferedImage bufferedImage = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_RGB);

            Graphics2D g = bufferedImage.createGraphics();
            boolean useTransform = false;
            if (useTransform) {// use transfrom to draw
                //log.trace("use transform");
                g.drawImage(srcImage, tx, null);
            } else {// use java filter
                //log.trace("use filter");
                Image scaleImage = getScaledInstance(srcImage, imgWidth, imgHeight);
                g.drawImage(scaleImage, 0, 0, null);
            }
            g.dispose();// free resource

            // write it to disk
            outputStream = new FileOutputStream(thumbnailFile);
            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(outputStream);
            encoder.encode(bufferedImage);
        } catch (IOException e) {
            log.error("Error", e);
            throw e;
        } finally {// this finally is very important
            inputStream.close();
            if (outputStream != null) outputStream.close();
        }
    }

    /**
     * This method returns a fit-sized image for a source image,
     * this method retains the ratio of the source image
     */
    public static Image getFitSizeImage(Image srcImage, int fitWidth, int fitHeight)
        throws IOException {
        if ((fitWidth < 100) || (fitHeight < 100)) throw new IllegalArgumentException("Cannot accept values < 100");

        int srcWidth  = srcImage.getWidth(null);//xem lai cho nay vi neu dung BufferedImage thi khong can null
        int srcHeight = srcImage.getHeight(null);
        //log.trace("src w = " + srcWidth + " h = " + srcHeight);

        // dont need any transforms
        if ((srcWidth == fitWidth) && (srcHeight == fitHeight)) return srcImage;

        int newWidth  = srcWidth;
        int newHeight = srcHeight;

        double fitRatio = (double)fitWidth / fitHeight;
        double srcRatio = (double)srcWidth / srcHeight;
        if (srcRatio > fitRatio) {// must cut the width of the source image
            newWidth = (int)(srcHeight * fitRatio);
        } else {// must cut the height of the source image
            newHeight = (int)(srcWidth / fitRatio);
        }
        //log.trace("new w = " + newWidth + " h = " + newHeight);

        ImageFilter cropFilter = new CropImageFilter((srcWidth-newWidth)/2, (srcHeight-newHeight)/2, newWidth, newHeight);
        ImageProducer cropProd = new FilteredImageSource(srcImage.getSource(), cropFilter);
        Image cropImage = Toolkit.getDefaultToolkit().createImage(cropProd);

        Image retImage = new ImageIcon(getScaledInstance(cropImage, fitWidth, fitHeight)).getImage();

        return retImage;
    }

    /**
     * This method returns a fit-sized image for a source image,
     * this method retains the ratio of the source image
     */
    public static Image getFitSizeImage(InputStream inputStream, int fitWidth, int fitHeight)
        throws IOException {
        try {
            JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(inputStream);
            BufferedImage srcImage = decoder.decodeAsBufferedImage();

            return getFitSizeImage(srcImage, fitWidth, fitHeight);
        } catch (IOException e) {
            log.error("Cannot run getFitSizeImage", e);
            throw e;
        } finally {// this finally is very important
            inputStream.close();
        }
    }

    /**
     * This method write the image to a stream.
     * It auto detect the image is Image or BufferedImage.
     * This method close the output stream before it return.
     *
     * @param image Image
     * @param outputStream OutputStream
     * @throws IOException
     */
    public static void writeJpegImage_Sun(Image image, OutputStream outputStream) throws IOException {

        if (outputStream == null) {
            return;
        }

        try {
            BufferedImage bufferedImage = null;
            if (image instanceof BufferedImage) {
                bufferedImage = (BufferedImage)image;
            } else {
                // 30% cpu resource
                bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null),
                                                  BufferedImage.TYPE_INT_RGB);

                // 7.5 cpu
                Graphics2D g = bufferedImage.createGraphics();

                // 50% cpu
                g.drawImage(image, 0, 0, null);
                g.dispose(); // free resource
            }

            // write it to disk
            // 12% cpu
            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(outputStream);
            encoder.encode(bufferedImage);
        } finally {
            try {
                if (outputStream != null) {
                    outputStream.close();
                }
            } catch (IOException ex1) {
            }
        }
    }

    public static void writeJpegImage_Sun(Image image, String fileName) throws IOException {
        OutputStream outputStream = new FileOutputStream(fileName);
        writeJpegImage_Sun(image, outputStream);
    }

    /**
     * This method write image to output stream, then it close the stream before return
     *
     * @param image Image
     * @param outputStream OutputStream
     * @throws IOException
     */
    public static void writeJpegImage_nonSun(Image image, OutputStream outputStream) throws IOException {
        if (outputStream == null) {
            return;
        }
        try {
            JpegEncoder encoder = new JpegEncoder(image, 80, outputStream);
            encoder.Compress();
        } catch (Exception ex) {
        } finally {
            try {
                if (outputStream != null) {
                    outputStream.close();
                }
            } catch (IOException ex1) {
            }
        }
    }

    public static void writeJpegImage_nonSun(Image image, String fileName) throws IOException {
        OutputStream outputStream = new FileOutputStream(fileName);

        //this method will close the stream before it returns so no need to close
        writeJpegImage_nonSun(image, outputStream);
    }

    public static Image getScaledInstance(Image srcImage, int width, int height) {
        boolean useSun = false;
        ImageFilter filter;
        if (useSun){
            //log.trace("use sun scalefilter");
            filter = new java.awt.image.AreaAveragingScaleFilter(width, height);
        } else {
            //log.trace("use nguoimau scalefilter");
            filter = new net.myvietnam.mvncore.util.AreaAveragingScaleFilter(width, height);
        }
        ImageProducer prod = new FilteredImageSource(srcImage.getSource(), filter);
        Image newImage = Toolkit.getDefaultToolkit().createImage(prod);
        ImageIcon imageIcon = new ImageIcon(newImage);
        return imageIcon.getImage();
    }
/*
    public static void main(String[] args) {
        try {
            FileInputStream is = new FileInputStream("c:\\PUTTY.RND");
            createThumbnail(is, "c:\\out.jpg", 120, 120);

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
中文字幕一区在线观看| 精品亚洲国产成人av制服丝袜| 亚洲成av人**亚洲成av**| 国精产品一区一区三区mba桃花 | 国产精品午夜春色av| 亚洲美腿欧美偷拍| 国产精品一二三区在线| 欧美日韩国产影片| 亚洲色图欧美偷拍| 国产电影一区在线| 日韩精品资源二区在线| 五月婷婷综合在线| 欧美在线免费播放| 1024成人网| 粉嫩aⅴ一区二区三区四区| 欧美α欧美αv大片| 日韩精品久久久久久| 在线看日韩精品电影| 中文字幕国产精品一区二区| 精品一区二区成人精品| 欧美一区在线视频| 天堂久久久久va久久久久| 欧美系列日韩一区| 亚洲一区av在线| 欧美性受极品xxxx喷水| 亚洲欧美另类久久久精品| 99riav一区二区三区| 日本一区二区三区国色天香 | 午夜视频在线观看一区二区| 91在线视频18| 中文字幕一区二区三区不卡在线| 成人午夜激情视频| 国产精品不卡在线观看| 97精品国产97久久久久久久久久久久| 国产精品国产精品国产专区不蜜 | 色天天综合色天天久久| 一区二区三区.www| 欧美综合欧美视频| 日韩国产在线一| 日韩欧美国产精品一区| 国产一区激情在线| 亚洲国产精品t66y| 色综合色综合色综合| 亚洲综合激情小说| 欧美一区二区三区男人的天堂| 日韩电影在线观看电影| 亚洲精品一区在线观看| 国产成人精品1024| 综合婷婷亚洲小说| 欧美老女人在线| 国内精品免费在线观看| 国产精品麻豆欧美日韩ww| 色香蕉成人二区免费| 亚洲已满18点击进入久久| 91精品久久久久久久久99蜜臂| 日本不卡不码高清免费观看| 久久久久青草大香线综合精品| 播五月开心婷婷综合| 亚洲一区二区三区视频在线播放 | 91精品婷婷国产综合久久性色| 麻豆一区二区三区| 国产精品国产三级国产aⅴ原创 | 国产91色综合久久免费分享| 亚洲欧美日韩久久精品| 91精品国产综合久久国产大片 | 欧美国产成人在线| 色欧美88888久久久久久影院| 欧美a级理论片| 国产精品免费网站在线观看| 欧美偷拍一区二区| 国产.欧美.日韩| 亚洲成人免费视频| 国产精品久久久久久久午夜片| 精品视频一区二区不卡| 国产成人午夜精品影院观看视频| 亚洲人精品午夜| www欧美成人18+| 欧美中文字幕一区二区三区亚洲| 六月丁香综合在线视频| 亚洲欧美综合网| 精品国产免费人成电影在线观看四季 | 国产精品色婷婷| 欧美精品一级二级| 97久久超碰国产精品电影| 黄色日韩网站视频| 日韩成人av影视| 亚洲精品你懂的| 国产精品丝袜一区| 欧美精品一区二区三区蜜桃视频| 欧美又粗又大又爽| 99国产精品久久久久久久久久 | 国产精品理伦片| 精品久久久三级丝袜| 欧美三区在线观看| 一本大道av一区二区在线播放 | 国产精品素人视频| 久久一夜天堂av一区二区三区 | 欧美性猛交xxxx乱大交退制版| 成人午夜精品在线| 国产乱码精品一品二品| 欧美aaa在线| 日韩国产精品大片| 天天操天天干天天综合网| 亚洲综合一区二区精品导航| 国产精品久久久久精k8| 欧美激情在线一区二区三区| 久久免费精品国产久精品久久久久| 欧美调教femdomvk| 欧美日韩一二区| 欧洲一区在线电影| 欧美午夜在线一二页| 欧美在线短视频| 欧美午夜精品电影| 欧美日韩综合在线| 欧美性色欧美a在线播放| 在线一区二区三区| 欧美天堂一区二区三区| 欧美日韩国产欧美日美国产精品| 色老汉av一区二区三区| 欧洲一区二区av| 欧美丰满美乳xxx高潮www| 欧美日韩一级视频| 69久久夜色精品国产69蝌蚪网| 欧美婷婷六月丁香综合色| 精品视频一区三区九区| 7777精品久久久大香线蕉| 欧美一区午夜视频在线观看| 7777精品伊人久久久大香线蕉| 日韩女优制服丝袜电影| 久久久久久免费网| 国产精品乱人伦一区二区| 综合自拍亚洲综合图不卡区| 亚洲综合男人的天堂| 久久精品国产免费看久久精品| 精品一区二区三区影院在线午夜| 国产又黄又大久久| 91在线国产观看| 欧美日韩免费一区二区三区| 欧美一区午夜精品| 国产精品拍天天在线| 亚洲黄色在线视频| 久久激情五月婷婷| av不卡免费在线观看| 欧美美女直播网站| 久久天堂av综合合色蜜桃网| 国产精品久久久久久亚洲毛片| 亚洲一区二区在线播放相泽| 毛片一区二区三区| 99久久久免费精品国产一区二区| 在线播放中文字幕一区| 欧美高清在线一区二区| 亚洲成人激情社区| 国产成人激情av| 欧美日韩亚洲综合在线 | 2023国产精品自拍| 洋洋av久久久久久久一区| 麻豆精品一区二区| 97精品超碰一区二区三区| 欧美大片日本大片免费观看| 亚洲天堂精品视频| 久久福利资源站| 欧美无砖专区一中文字| 国产精品视频一区二区三区不卡| 日韩av二区在线播放| 99视频在线精品| 久久婷婷综合激情| 免费人成精品欧美精品| 色爱区综合激月婷婷| 国产蜜臀97一区二区三区| 人人超碰91尤物精品国产| 色噜噜狠狠成人中文综合 | 天天射综合影视| 99免费精品视频| 欧美激情综合网| 久久精品国产一区二区三区免费看| 欧美综合亚洲图片综合区| 国产精品伦理一区二区| 国内成人精品2018免费看| 欧美探花视频资源| 一区二区三区在线观看动漫| 国产成人啪免费观看软件| 精品噜噜噜噜久久久久久久久试看 | 一区二区三区中文字幕精品精品 | 亚洲在线中文字幕| 92国产精品观看| 国产精品久久久久国产精品日日| 国产一本一道久久香蕉| 久久嫩草精品久久久久| 久久精品99国产精品日本| 51午夜精品国产| 日韩影院精彩在线| 欧美猛男超大videosgay| 午夜日韩在线观看| 欧美三级三级三级爽爽爽| 亚洲小少妇裸体bbw| 欧美性做爰猛烈叫床潮| 亚洲成人免费在线观看| 欧美日韩精品专区| 天天操天天综合网| 日韩一区二区在线观看视频播放|