📄 imageutils.java
字号:
/* * ImageUtils.java * * Created on 2007-11-6, 14:58:52 * * To change this template, choose Tools | Templates * and open the template in the editor. */package com.s7turn.sdk.utils;import com.sun.jimi.core.Jimi;import com.sun.jimi.core.JimiException;import com.sun.jimi.core.raster.JimiRasterImage;import java.awt.Image;import java.io.BufferedOutputStream;import java.io.ByteArrayInputStream;import java.io.InputStream;import java.io.OutputStream;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;/** * * @author Long */public class ImageUtils { private static Log logger = LogFactory.getLog( ImageUtils.class ); public static boolean resizeImage( byte[] bufferImage, int width, int height, String outputType, OutputStream output ) { OutputStream bufferOutput = null; try { InputStream imageStream = new ByteArrayInputStream ( bufferImage ); Image img = Jimi.getImage( imageStream ); int orgWidth = img.getWidth(null); int orgHeight = img.getHeight(null); float Wscale = (float) width / (float) orgWidth; float Hscale = (float) height / (float) orgHeight; float scale = Wscale > Hscale ? Hscale : Wscale; Image scaledImage = img.getScaledInstance((int) (orgWidth * scale), (int) ( orgHeight * scale ), Image.SCALE_SMOOTH ); JimiRasterImage raster = Jimi.createRasterImage( scaledImage.getSource() ); bufferOutput = new BufferedOutputStream( output ); Jimi.putImage( outputType, raster, bufferOutput); } catch (JimiException ex) { logger.error(ex.getMessage(), ex); return false; } finally { if( bufferOutput != null ) { try{ bufferOutput.flush(); bufferOutput.close(); }catch(Exception e){} } } return true; } public static boolean resizeImage(byte[] bufferImage, int width, int height, OutputStream output) { return resizeImage( bufferImage, width, height, "image/jpeg", output ); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -