当前位置: 首页>>代码示例>>Java>>正文


Java CropImageFilter类代码示例

本文整理汇总了Java中java.awt.image.CropImageFilter的典型用法代码示例。如果您正苦于以下问题:Java CropImageFilter类的具体用法?Java CropImageFilter怎么用?Java CropImageFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CropImageFilter类属于java.awt.image包,在下文中一共展示了CropImageFilter类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: cut

import java.awt.image.CropImageFilter; //导入依赖的package包/类
/**
 * 图像切割(指定切片的宽度和高度)
 * @param bi 原图像
 * @param x 裁剪原图像起点坐标X
 * @param y 裁剪原图像起点坐标Y
 * @param width 目标切片宽度
 * @param height 目标切片高度
 * @return
 */
public static BufferedImage cut(BufferedImage bi,int x, int y, int width, int height) {

    BufferedImage tag = new BufferedImage(width, height,
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = tag.createGraphics();
    tag = g2.getDeviceConfiguration().createCompatibleImage(width, height,
            Transparency.TRANSLUCENT);
    g2.dispose();
    g2 = tag.createGraphics();

    int srcWidth = bi.getHeight(); // 源图宽度
    int srcHeight = bi.getWidth(); // 源图高度
    if (srcWidth > 0 && srcHeight > 0) {
        ImageFilter cropFilter = new CropImageFilter(x, y, width, height);
        Image img = Toolkit.getDefaultToolkit().createImage(
                new FilteredImageSource(bi.getSource(),cropFilter));
        g2.drawImage(img, 0, 0, width, height, null); // 绘制切割后的图
        g2.dispose();
    }
    return tag;
}
 
开发者ID:QianLongGit,项目名称:imageServer,代码行数:31,代码来源:ImageUtil.java

示例2: cut

import java.awt.image.CropImageFilter; //导入依赖的package包/类
/**
 * 图像切割(按指定起点坐标和宽高切割)
 * @param srcImg 源图像地址
 * @param outImg 切片后的图像地址
 * @param x 目标切片起点坐标X
 * @param y 目标切片起点坐标Y
 * @param width 目标切片宽度
 * @param height 目标切片高度
 * @param imageType 图片类型
 */
public static void cut(File srcImg, File outImg, int x, int y, int width, int height,String imageType) throws Exception{
	//读取源图像
	BufferedImage bi = ImageIO.read(srcImg);
	int srcWidth = bi.getHeight();//源图宽度
	int srcHeight = bi.getWidth();//源图高度
	if (srcWidth > 0 && srcHeight > 0) {
		Image image = bi.getScaledInstance(srcWidth, srcHeight,Image.SCALE_DEFAULT);
		//四个参数分别为图像起点坐标和宽高
		//即:CropImageFilter(int x,int y,int width,int height)
		ImageFilter cropFilter = new CropImageFilter(x, y, width,height);
		Image img = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(image.getSource(), cropFilter));
		BufferedImage tag = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
		Graphics g = tag.getGraphics();
		g.drawImage(img, 0, 0, width, height, null);//绘制切割后的图
		g.dispose();
		//输出为文件
		ImageIO.write(tag, imageType, outImg);
	}
}
 
开发者ID:tank2140896,项目名称:JavaWeb,代码行数:30,代码来源:ImageUtils.java

示例3: imageClip

import java.awt.image.CropImageFilter; //导入依赖的package包/类
/**
 * Image clip.
 *
 * @param g
 *            the g
 * @param ci
 *            the ci
 */
private void imageClip(Graphics2D g, CanvasInfo ci) {
	URL u;
	try {
		u = new URL(ci.getImage().getSrc());
		URLConnection con = u.openConnection();
		con.setRequestProperty("User-Agent", UserAgentContext.DEFAULT_USER_AGENT);
		Image img = ImageIO.read(con.getInputStream());
		img = createImage(new FilteredImageSource(img.getSource(),
				new CropImageFilter(ci.getSx(), ci.getSy(), ci.getSw(), ci.getSh())));
		g.clip(new Rectangle2D.Float(ci.getDx(), ci.getDy(), ci.getDw(), ci.getDh()));
		g.drawImage(img, ci.getDx(), ci.getDy(), ci.getDw(), ci.getDh(), this);
	} catch (Exception e) {
		logger.error(e.getLocalizedMessage());
	}
}
 
开发者ID:oswetto,项目名称:LoboEvolution,代码行数:24,代码来源:CanvasControl.java

示例4: cut

import java.awt.image.CropImageFilter; //导入依赖的package包/类
public Jimage cut(int x, int y, int width, int height) {
    try {
        BufferedImage bi = this.imageis;
        int srcWidth = bi.getHeight();
        int srcHeight = bi.getWidth();
        if (srcWidth > 0 && srcHeight > 0) {
            Image imagex = bi.getScaledInstance(srcWidth, srcHeight, Image.SCALE_DEFAULT);
            ImageFilter cropFilter = new CropImageFilter(x, y, width, height);
            Image img = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(imagex.getSource(), cropFilter));
            BufferedImage tag = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
            Graphics g = tag.getGraphics();
            g.drawImage(img, 0, 0, width, height, null); // 绘制切割后的图
            g.dispose();
            this.imageis = tag;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return this;
}
 
开发者ID:hou80houzhu,项目名称:rocserver,代码行数:21,代码来源:Jimage.java

示例5: cut

import java.awt.image.CropImageFilter; //导入依赖的package包/类
/**
 * 图像切割(按指定起点坐标和宽高切割)
 * @param srcImageFile 源图像地址
 * @param result 切片后的图像地址
 * @param x 目标切片起点坐标X
 * @param y 目标切片起点坐标Y
 * @param width 目标切片宽度
 * @param height 目标切片高度
 */
public final static void cut(File src, File tar, int x, int y, int width, int height) {
    try {
        // 读取源图像
        BufferedImage bi = ImageIO.read(src);
        int srcWidth = bi.getHeight(); // 源图宽度
        int srcHeight = bi.getWidth(); // 源图高度
        if (srcWidth > 0 && srcHeight > 0) {
            Image image = bi.getScaledInstance(srcWidth, srcHeight, Image.SCALE_DEFAULT);
            // 四个参数分别为图像起点坐标和宽高
            // 即: CropImageFilter(int x,int y,int width,int height)
            ImageFilter cropFilter = new CropImageFilter(x, y, width, height);
            Image img = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(image.getSource(), cropFilter));
            BufferedImage tag = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
            Graphics g = tag.getGraphics();
            g.drawImage(img, 0, 0, width, height, null); // 绘制切割后的图
            g.dispose();
            // 输出为文件

            File dir = tar.getParentFile();
            if(!dir.exists()){
            	dir.mkdirs();
            }
            ImageIO.write(tag, "JPEG", tar);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:anylineorg,项目名称:anyline,代码行数:38,代码来源:ImgUtil.java

示例6: cut

import java.awt.image.CropImageFilter; //导入依赖的package包/类
/**
 * 图像切割(按指定起点坐标和宽高切割)
 * 
 * @param is
 *            源图像输入流
 * @param os
 *            切割后输出流
 * @param x
 *            目标切片起点坐标X
 * @param y
 *            目标切片起点坐标Y
 * @param width
 *            目标切片宽度
 * @param height
 *            目标切片高度
 */
public final static void cut(InputStream is, OutputStream os, int x, int y,
		int width, int height) {
	try {
		// 读取源图像
		BufferedImage bi = ImageIO.read(is);
		int srcWidth = bi.getHeight(); // 源图宽度
		int srcHeight = bi.getWidth(); // 源图高度
		if (srcWidth > 0 && srcHeight > 0) {

			Image image = bi.getScaledInstance(srcWidth, srcHeight,
					Image.SCALE_DEFAULT);
			// 四个参数分别为图像起点坐标和宽高
			ImageFilter cropFilter = new CropImageFilter(x, y, width,
					height);
			Image img = Toolkit.getDefaultToolkit().createImage(
					new FilteredImageSource(image.getSource(), cropFilter));
			BufferedImage tag = new BufferedImage(width, height,
					BufferedImage.TYPE_INT_RGB);
			Graphics g = tag.getGraphics();
			g.drawImage(img, 0, 0, width, height, null); // 绘制切割后的图
			g.dispose();
			// 输出为文件
			ImageIO.write(tag, IMAGE_TYPE_JPEG, os);
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:kiwilew,项目名称:covito-kit,代码行数:45,代码来源:ImageUtil.java

示例7: main

import java.awt.image.CropImageFilter; //导入依赖的package包/类
public static void main (String[] args) {
    new CropImageFilter(20, 20, 40, 50).clone();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:4,代码来源:HeadlessCropImageFilter.java

示例8: define

import java.awt.image.CropImageFilter; //导入依赖的package包/类
public void define() {
	room = new Room();
	save = new Save();
	store = new Store();
	
	for(int i = 0; i < tileset_ground.length; i++) {
		tileset_ground[i] = new ImageIcon("res" + File.separator + "tileset_ground.png").getImage();
		if(Frame.BigRes) {
			tileset_ground[i] = createImage(new FilteredImageSource(tileset_ground[i].getSource(), new CropImageFilter(0, room.blockSize*i/2, room.blockSize/2, room.blockSize/2)));	
		} else {
			tileset_ground[i] = createImage(new FilteredImageSource(tileset_ground[i].getSource(), new CropImageFilter(0, room.blockSize*i, room.blockSize, room.blockSize)));
		}
	}
	for(int i = 0; i < tileset_air.length; i++) {
		tileset_air[i] = new ImageIcon("res" + File.separator + "tileset_air.png").getImage();
		if(Frame.BigRes) {
			tileset_air[i] = createImage(new FilteredImageSource(tileset_air[i].getSource(), new CropImageFilter(0, room.blockSize*i/2, room.blockSize/2, room.blockSize/2)));
		} else {
			tileset_air[i] = createImage(new FilteredImageSource(tileset_air[i].getSource(), new CropImageFilter(0, room.blockSize*i, room.blockSize, room.blockSize)));
		}
	}
	
	tileset_res[0] = new ImageIcon("res" + File.separator + "cell.png").getImage();
	tileset_res[1] = new ImageIcon("res" + File.separator + "heart.png").getImage();
	tileset_res[2] = new ImageIcon("res" + File.separator + "coin.png").getImage();
	tileset_res[3] = new ImageIcon("res" + File.separator + "level.png").getImage();
	
	tileset_mob[0] = new ImageIcon("res" + File.separator + "mob.png").getImage();
	
	firstSpawn = true;
	spawnFrame = 0;
	
	health = 100;
	
	try {
	
		if(saveFile.exists()) {
			saveFileExists = true;
		} else {
			saveFileExists = false;
			File tmpCreateFolder = new File("save");
			tmpCreateFolder.mkdirs();
			saveFile.createNewFile();
		}
		
		if(newLaunch) {
			newLaunch = false;
			if(saveFileExists) {
				Scanner loadScanner = new Scanner(saveFile);
				while(loadScanner.hasNext()) {
					startingLevel = loadScanner.nextInt();	
				}
				loadScanner.close();
			}	
		}
		
		File loadLevelFile = new File("levels" + File.separator + "mission" + startingLevel + ".btd"); 
		if(loadLevelFile.exists()) {
			save.loadSave(loadLevelFile);	
		} else {
			isGameEnding = true;
			loadLevelFile = new File("levels" + File.separator + "mission" + 1 + ".btd"); 
			save.loadSave(loadLevelFile);
		}
		
	} catch (Exception e) {}
	
	Store.towerCounter = 0;
	
	for(int i = 0; i < mobs.length; i++) {
		mobs[i] = new Mob();
	}
}
 
开发者ID:Bleuzen,项目名称:TowerDefense,代码行数:74,代码来源:Screen.java


注:本文中的java.awt.image.CropImageFilter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。