⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imageutils.java

📁 Skin Look And Feel 1.2.10, 给你的java程序换肤, 支持大量通用皮肤文件.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* ====================================================================
 *
 * Skin Look And Feel 1.2.10 License.
 *
 * Copyright (c) 2000-2004 L2FProd.com.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution, if
 *    any, must include the following acknowlegement:
 *       "This product includes software developed by L2FProd.com
 *        (http://www.L2FProd.com/)."
 *    Alternately, this acknowlegement may appear in the software itself,
 *    if and wherever such third-party acknowlegements normally appear.
 *
 * 4. The names "Skin Look And Feel", "SkinLF" and "L2FProd.com" must not
 *    be used to endorse or promote products derived from this software
 *    without prior written permission. For written permission, please
 *    contact info@L2FProd.com.
 *
 * 5. Products derived from this software may not be called "SkinLF"
 *    nor may "SkinLF" appear in their names without prior written
 *    permission of L2FProd.com.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL L2FPROD.COM OR ITS CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * ====================================================================
 */
package com.l2fprod.util;

import com.l2fprod.contrib.freehep.PanelArtistUtilities;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.awt.image.FilteredImageSource;
import java.awt.image.MemoryImageSource;
import java.awt.image.PixelGrabber;
import java.awt.image.RGBImageFilter;
import java.awt.image.WritableRaster;

import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.plaf.ColorUIResource;

/**
 * @author    $Author: l2fprod $
 * @created   27 avril 2002
 * @version   $Revision: 1.6 $, $Date: 2004/07/29 19:10:28 $
 */
public final class ImageUtils implements SwingConstants {

	/**
	 * Description of the Field
	 */
	public final static Component producer = new java.awt.Component() {
	};

	/**
	 * Description of the Field
	 */
	public final static int PAINT_NORMAL = 0;
	/**
	 * Description of the Field
	 */
	public final static int PAINT_STRETCH = 1;
	/**
	 * Description of the Field
	 */
	public final static int PAINT_TILE = 2;
	/**
	 * Description of the Field
	 */
	public final static int PAINT_CENTERED = 3;
	/**
	 * Description of the Field
	 */
	public final static int PAINT_NONE = 5;

	/**
	 * Description of the Field
	 */
	public final static int TRANSPARENT_RED = 255;
	/**
	 * Description of the Field
	 */
	public final static int TRANSPARENT_GREEN = 0;
	/**
	 * Description of the Field
	 */
	public final static int TRANSPARENT_BLUE = 255;
	/**
	 * Description of the Field
	 */
	public final static int TRANSPARENT_TO_REMOVE = new Color(255, 0, 255).getRGB();
	/**
	 * Description of the Field
	 */
	public final static int TRANSPARENT_PIXEL = new Color(255, 0, 0, 0).getRGB();

	/**
	 * Gets the DisabledIcon attribute of the ImageUtils class
	 *
	 * @param anIcon  Description of Parameter
	 * @return        The DisabledIcon value
	 */
	public static ImageIcon getDisabledIcon(ImageIcon anIcon) {
		return getDisabledIcon(anIcon.getImage());
	}

	/**
	 * Gets the DisabledIcon attribute of the ImageUtils class
	 *
	 * @param anImage  Description of Parameter
	 * @return         The DisabledIcon value
	 */
	public static ImageIcon getDisabledIcon(Image anImage) {
		return new ImageIcon(getDisabledImage(anImage));
	}

	/**
	 * Gets the DisabledImage attribute of the ImageUtils class
	 *
	 * @param anImage  Description of Parameter
	 * @return         The DisabledImage value
	 */
	public static Image getDisabledImage(Image anImage) {
		if (anImage == null) {
			return null;
		} else {
			return filterImage(new javax.swing.GrayFilter(true, 75), anImage);
		}
	}

	/**
	 * Description of the Method
	 *
	 * @param filter  Description of Parameter
	 * @param image   Description of Parameter
	 * @return        Description of the Returned Value
	 */
	public static Image filterImage(RGBImageFilter filter, Image image) {
		return producer.createImage(new FilteredImageSource(image.getSource(), filter));
	}

	/**
	 * Description of the Method
	 *
	 * @param anImage  Description of Parameter
	 * @return         Description of the Returned Value
	 */
	public static Image rotateImage(Image anImage) {
		int w = anImage.getWidth(null);
		int h = anImage.getHeight(null);
		int[] pixels = new int[w * h];

		PixelGrabber pixel = new PixelGrabber(anImage, 0, 0, w, h, pixels, 0, w);
		try {
			pixel.grabPixels();
		} catch (Exception e) {
			//	    e.printStackTrace();
		}

		int[] rot = new int[h * w];
		int pos = 0;

		for (int i = w; i > 0; i--) {
			for (int j = 0; j < h; j++) {
				rot[pos] = pixels[i + (w * j) - 1];
				pos++;
			}
		}

		return convertBytesToImage(producer, rot, h, w);
	}

	/**
	 * Description of the Method
	 *
	 * @param anImage  Description of Parameter
	 * @param angle    Description of Parameter
	 * @return         Description of the Returned Value
	 */
	public static Image rotateImage(Image anImage, double angle) {
		int width = anImage.getWidth(null);
		int height = anImage.getHeight(null);
		int[] pixels = new int[width * height];

		PixelGrabber pixel = new PixelGrabber(anImage, 0, 0, width, height, pixels, 0, width);
		try {
			pixel.grabPixels();
		} catch (Exception e) {
			//    e.printStackTrace();
		}

		int[] pixels2 = new int[width * height];

		int i = 0;
		double radians = -angle / (180 / Math.PI);
		double cos = Math.cos(radians);
		double sin = Math.sin(radians);
		int centerX = width >> 1;
		int centerY = height >> 1;
		for (int oldY = -centerY; oldY < centerY; oldY++) {
			for (int oldX = -centerX; oldX < centerX; oldX++) {
				int newX = centerX + (int) ((oldX * cos) - (oldY * sin));
				int newY = centerY + (int) ((oldX * sin) + (oldY * cos));
				if (newX > 0 && newX < width && newY > 0 && newY < height) {
					pixels2[i++] = pixels[(width * newY) + newX];
				} else {
					pixels2[i++] = pixels[0];
				}
			}
		}
		return producer.createImage(new MemoryImageSource(width, height, pixels2, 0, width));
	}

	/**
	 * Description of the Method
	 *
	 * @param c       Description of Parameter
	 * @param pixels  Description of Parameter
	 * @param w       Description of Parameter
	 * @param h       Description of Parameter
	 * @return        Description of the Returned Value
	 */
	public static Image convertBytesToImage(Component c, int[] pixels, int w, int h) {
		return c.createImage(new MemoryImageSource(w, h, pixels, 0, w));
	}

	/**
	 * Description of the Method
	 *
	 * @param c      Description of Parameter
	 * @param g      Description of Parameter
	 * @param image  Description of Parameter
	 */
	public static void paint(Component c, Graphics g, Image image) {
		paint(c, g, image, true);
	}

	/**
	 * Description of the Method
	 *
	 * @param c          Description of Parameter
	 * @param g          Description of Parameter
	 * @param image      Description of Parameter
	 * @param paintType  Description of Parameter
	 */
	public static void paint(Component c, Graphics g, Image image, int paintType) {
		paint(c, g, image, true, paintType);
	}

	/**
	 * Description of the Method
	 *
	 * @param c                Description of Parameter
	 * @param g                Description of Parameter
	 * @param image            Description of Parameter
	 * @param alignWithParent  Description of Parameter
	 */
	public static void paint(Component c, Graphics g, Image image, boolean alignWithParent) {
		paint(c, g, image, alignWithParent, PAINT_STRETCH);
	}

	/**
	 * Description of the Method
	 *
	 * @param c                Description of Parameter
	 * @param g                Description of Parameter
	 * @param image            Description of Parameter
	 * @param alignWithParent  Description of Parameter
	 * @param paintType        Description of Parameter
	 */
	public static void paint(Component c, Graphics g, Image image, boolean alignWithParent, int paintType) {
		paint(c, g, image, 0, 0, ((JComponent)c).getWidth(), ((JComponent)c).getHeight(), alignWithParent, paintType);
	}

	/**
	 * Description of the Method
	 *
	 * @param c       Description of Parameter
	 * @param g       Description of Parameter
	 * @param image   Description of Parameter
	 * @param x       Description of Parameter
	 * @param y       Description of Parameter
	 * @param width   Description of Parameter
	 * @param height  Description of Parameter
	 */
	public static void paint(Component c, Graphics g, Image image, int x, int y, int width, int height) {
		paint(c, g, image, x, y, width, height, true, PAINT_STRETCH);

	}

	/**
	 * Description of the Method
	 *
	 * @param c          Description of Parameter
	 * @param g          Description of Parameter
	 * @param image      Description of Parameter
	 * @param x          Description of Parameter
	 * @param y          Description of Parameter
	 * @param width      Description of Parameter
	 * @param height     Description of Parameter
	 * @param paintType  Description of Parameter
	 */
	public static void paint(Component c, Graphics g, Image image, int x, int y, int width, int height, int paintType) {
		paint(c, g, image, x, y, width, height, true, paintType);
	}

	/**
	 * Description of the Method
	 *
	 * @param c                Description of Parameter
	 * @param g                Description of Parameter
	 * @param image            Description of Parameter
	 * @param x                Description of Parameter
	 * @param y                Description of Parameter
	 * @param width            Description of Parameter
	 * @param height           Description of Parameter
	 * @param alignWithParent  Description of Parameter
	 * @param paintType        Description of Parameter
	 */
	public static void paint(Component c, Graphics g, Image image, int x, int y, int width, int height, boolean alignWithParent, int paintType) {
		if (image == null) {
			return;
		}

⌨️ 快捷键说明

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