`
gudujianxuehu
  • 浏览: 97886 次
  • 来自: ...
社区版块
存档分类
最新评论

图片操作

阅读更多
用java实现图片处理中的透明效果,可以实现图片的合成,渐隐渐现

import java.awt.*;
import java.net.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import java.awt.image.*;

// 半透明图片

public class HalfTransparentImageDemo extends JFrame {
	private Container content = getContentPane(); //获得窗口的容器
 	private JSlider jSlider = new JSlider(JSlider.HORIZONTAL,0,100,75); //改变图像的透明度	
	DisplayPanel displayPanel = new DisplayPanel(); //显示图形面板

	public HalfTransparentImageDemo() {
		super("半透明图片"); //调用父类构造器
		jSlider.setPaintTicks(true);  //绘制标志位	
		jSlider.setMajorTickSpacing(25); //设置标志尺寸
		jSlider.setMinorTickSpacing(5);
		jSlider.setPaintLabels(true); //绘制出数字
		jSlider.setBorder(new TitledBorder(BorderFactory.createEmptyBorder(), "图像的透明度(%)")); //设置边框
		jSlider.addChangeListener(new ChangeListener() { //滑动条jSlider事件处理
			public void stateChanged(ChangeEvent ce) {
				float alpha =((float) ((JSlider) ce.getSource()).getValue()) / 100;
				displayPanel.alpha = alpha; //改变图像的透明度
				displayPanel.repaint(); //重绘displayPanel
			}
		});
		content.add(jSlider, BorderLayout.SOUTH); //增加组件到容器上
		content.add(displayPanel, BorderLayout.CENTER);
		setSize(300, 300); //设置窗口尺寸
		setVisible(true); //设置窗口可视
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //关闭窗口时退出程序
	}
	
	public static void main(String[] args) {
		new HalfTransparentImageDemo();
	}
	
	//显示图形的面板
	class DisplayPanel extends JPanel {
		String[] imageName = { "back.jpg", "girl.gif" }; //图像文件名数组
		BufferedImage bufImage1, bufImage2; //缓冲区图像
		float alpha = 0.75f; // 图像合成的alpha赋初值
		
		//根据Image对象创建一个缓冲区图像
		public BufferedImage loadBufImage(String fileName) {
			Image image = getToolkit().getImage(fileName); //获取Image对象
			MediaTracker mt = new MediaTracker(this); //实例化媒体加载器
			mt.addImage(image, 0); //增加待加载Image对象
			try {
				mt.waitForAll(); //等待图片加载
			} catch (Exception e) {
				e.printStackTrace(); //输出错误信息
			}					
			BufferedImage bufImage =new BufferedImage(image.getWidth(this),image.getHeight(this),BufferedImage.TYPE_INT_ARGB); //创建缓冲区图像	
     		Graphics bufImageG2D = bufImage.createGraphics(); //创建缓冲区图像的图形环境	
			bufImageG2D.drawImage(image, 0, 0, this); //在图形环境绘制图像
			return bufImage; //返回缓冲区图像对象
		}
	
		public DisplayPanel() {
			bufImage1=loadBufImage(imageName[0]);  //创建缓冲区图像1
			bufImage2=loadBufImage(imageName[1]);  //创建缓冲区图像2
		}
	
		public void paint(Graphics g) {
			Graphics2D g2d = (Graphics2D) g;
			g2d.drawImage(bufImage1, 0, 0, this); //在图形环境绘制缓冲区图像1
			g2d.drawString("Destination",5,20);  //绘制文字			
			int compositeRule = AlphaComposite.SRC_OVER; //源排斥目标法合成规则			
			AlphaComposite alphaComposite=AlphaComposite.getInstance(compositeRule,alpha); //创建AlphaComposite对象
			g2d.setComposite(alphaComposite); //设置图形环境的合成方式			
			g2d.drawImage(bufImage2, 0, 0, this); //在图形环境绘制缓冲区图像2
			g2d.drawString("Source",150,20);  //绘制文字
		}	
	}
}




图片加水印或文字


import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import javax.imageio.ImageIO;

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

public final class ImageUtils {
	public ImageUtils() {

	}

	/**
	 * 把图片印刷到图片上
	 * 
	 * @param pressImg
	 *            -- 水印文件
	 * @param targetImg
	 *            -- 目标文件
	 * @param x
	 * @param y
	 */
	public final static void pressImage(String pressImg, String targetImg,
			int x, int y) {
		try {
			File _file = new File(targetImg);
			Image src = ImageIO.read(_file);
			int wideth = src.getWidth(null);
			int height = src.getHeight(null);
			BufferedImage image = new BufferedImage(wideth, height,
					BufferedImage.TYPE_INT_RGB);
			Graphics g = image.createGraphics();
			g.drawImage(src, 0, 0, wideth, height, null);

			// 水印文件
			File _filebiao = new File(pressImg);
			Image src_biao = ImageIO.read(_filebiao);
			int wideth_biao = src_biao.getWidth(null);
			int height_biao = src_biao.getHeight(null);
			g.drawImage(src_biao, wideth - wideth_biao - x, height
					- height_biao - y, wideth_biao, height_biao, null);
			// /
			g.dispose();
			FileOutputStream out = new FileOutputStream(targetImg);
			JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
			encoder.encode(image);
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 打印文字水印图片
	 * 
	 * @param pressText
	 *            --文字
	 * @param targetImg
	 *            -- 目标图片
	 * @param fontName
	 *            -- 字体名
	 * @param fontStyle
	 *            -- 字体样式
	 * @param color
	 *            -- 字体颜色
	 * @param fontSize
	 *            -- 字体大小
	 * @param x
	 *            -- 偏移量
	 * @param y
	 */

	public static void pressText(String pressText, String targetImg,
			String fontName, int fontStyle, int color, int fontSize, int x,
			int y) {
		try {
			File _file = new File(targetImg);
			Image src = ImageIO.read(_file);
			int wideth = src.getWidth(null);
			int height = src.getHeight(null);
			BufferedImage image = new BufferedImage(wideth, height,
					BufferedImage.TYPE_INT_RGB);
			Graphics g = image.createGraphics();
			g.drawImage(src, 0, 0, wideth, height, null);

			g.setColor(Color.RED);
			g.setFont(new Font(fontName, fontStyle, fontSize));

			g.drawString(pressText, wideth - fontSize - x, height - fontSize
					/ 2 - y);
			g.dispose();

			FileOutputStream out = new FileOutputStream(targetImg);
			JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
			encoder.encode(image);
			out.close();
		} catch (Exception e) {
			System.out.println(e);
		}
	}

	public final static void pressImage2(String pressImg, String string, int x,
			int y) {
		try {
			File _file = new File(pressImg);
			File _file2 = new File(string);
			Image src = ImageIO.read(_file);
			int wideth = src.getWidth(null);
			int height = src.getHeight(null);
			BufferedImage image = new BufferedImage(wideth, height,
					BufferedImage.TYPE_INT_RGB);
			Graphics g = image.createGraphics();
			g.drawImage(src, 0, 0, wideth, height, null);
			int compositeRule = AlphaComposite.SRC_OVER; // 源排斥目标法合成规则
			AlphaComposite alphaComposite = AlphaComposite.getInstance(
					compositeRule, 0.25F); // 创建AlphaComposite对象
			((Graphics2D) g).setComposite(alphaComposite); // 设置图形环境的合成方式
			g.drawImage(ImageIO.read(_file2), 0, 0, null); // 在图形环境绘制缓冲区图像2
			g.dispose();
			FileOutputStream out = new FileOutputStream("d:/s.jpg");
			JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
			encoder.encode(image);
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) throws IOException {
		// pressImage("d:/1.gif ", "d:/2.jpg ", 20, 20);
		// pressText("wuwuuwuwuwu", "d:/2.jpg", "", 20, 10, 51, 811, 511);
		pressImage2("d:/1.jpg ", "d:/2.jpg", 20, 20);
	}
}




图片操作

import java.awt.Color;
import java.awt.color.ColorSpace;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.ColorConvertOp;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

/**
 * EasyImage lets you do all the basic image operations -  
 * converting, cropping, resizing, rotating, flipping?
 * Plus it let抯 you do some really cool affects.
 * All is done super easily.
 * Combining operations can produce some very cool results.
 * 
 * Operations:
    * Open image.
    * Save image
    * Convert image
    * Re-size image
    * Crop image
    * Convert to black and white image
    * Rotate image
    * Flip image
    * Add color to image
    * Create image with multiple instance of the original
    * Combining 2 images together
    * Emphasize parts of the image
    * Affine transform image
 *
 * 
 * @author Avi Yehuda
 *
 */
public class Image {
    private BufferedImage bufferedImage;
    private String fileName;
    
    /**
     * Constructor - loads from an image file.
     * @param imageFile
     */
    public Image(File imageFile) {
        try {
            bufferedImage = ImageIO.read(imageFile);
            fileName = imageFile.getAbsolutePath();
        } catch (Exception e) {
            e.printStackTrace();
            bufferedImage = null;
            imageFile = null;
        }
    }
    
    /**
     * Constructor - loads from an image file.
     * @param imageFilePath
     */
    public Image(String imageFilePath) {
        this(new File(imageFilePath));
    }
    
    /**
     * Return image as java.awt.image.BufferedImage
     * @return image as java.awt.image.BufferedImage
     */
    public BufferedImage getAsBufferedImage(){
        return bufferedImage;
    }
    
    /**
     * Save the image as a new image file.
     * Can also convert the image according to file type.
     * @param fileName
     */
    public void saveAs(String fileName){
        saveImage(new File(fileName));
        this.fileName = fileName;
    }
    
    
    /**
     * Saves the image to the original file.
     */
    public void save(){
        saveImage(new File(fileName));
    }
    
    
   
    /**
     * Resizing the image by percentage of the original.
     * @param percentOfOriginal
     */
    public void resize( int percentOfOriginal){
        int newWidth = bufferedImage.getWidth()  * percentOfOriginal / 100;
        int newHeight = bufferedImage.getHeight() * percentOfOriginal / 100;
        resize(newWidth, newHeight);
    }
        
    /**
     * Resizing the image by width and height. 
     * @param newWidth
     * @param newHeight
     */
    public void resize( int newWidth, int newHeight){
        
        int oldWidth = bufferedImage.getWidth();
        int oldHeight = bufferedImage.getHeight();
        
        if(newWidth == -1 || newHeight == -1){
            if(newWidth == -1){
                if(newHeight == -1){
                    return;
                } 
                
                newWidth = newHeight * oldWidth/ oldHeight;
            }
            else {
                newHeight = newWidth * oldHeight / oldWidth;
            }
        }
        
        BufferedImage result =
            new BufferedImage(newWidth , newHeight, BufferedImage.TYPE_INT_BGR);
        
        double widthSkip =  new Double(oldWidth-newWidth) / new Double(newWidth);
        double heightSkip =  new Double(oldHeight-newHeight) / new Double(newHeight);
        
        double widthCounter = 0;
        double heightCounter = 0;
        
        int newY = 0;
        
        boolean isNewImageWidthSmaller = widthSkip >0; 
        boolean isNewImageHeightSmaller = heightSkip >0; 
            
        for (int y = 0; y < oldHeight && newY < newHeight; y++) {
            
            if(isNewImageHeightSmaller && heightCounter > 1){ //new image suppose to be smaller - skip row
                heightCounter -= 1;
            }
            else if (heightCounter < -1){ //new image suppose to be bigger - duplicate row
                heightCounter += 1;
                
                if(y > 1)
                    y = y - 2;
                else
                    y = y - 1;
            }
            else{
               
                heightCounter += heightSkip;
                
                int newX = 0;
                
                for (int x = 0; x < oldWidth && newX < newWidth; x++) {
                   
                    if(isNewImageWidthSmaller && widthCounter > 1){ //new image suppose to be smaller - skip column
                        widthCounter -= 1;
                    }
                    else if (widthCounter < -1){ //new image suppose to be bigger - duplicate pixel
                        widthCounter += 1;
                        
                        if(x >1)
                            x = x - 2;
                        else
                            x = x - 1;
                    }
                    else{
                        
                        int rgb = bufferedImage.getRGB(x, y);
                        result.setRGB(newX, newY, rgb);
                        
                        newX++;
                        
                        widthCounter += widthSkip;
                    }
                    
                }
                
                newY++;
            }
            
            
            
        }
        
        
        bufferedImage = result;
    }
    
    /**
     * Add color to the RGB of the pixel
     * @param numToAdd
     */
    public void addPixelColor(int numToAdd){
        int width = bufferedImage.getWidth();
        int height = bufferedImage.getHeight();
        
        for (int x = 0; x < width; x ++) {
            for (int y = 0; y < height; y ++) {
                int rgb = bufferedImage.getRGB(x, y);
                bufferedImage.setRGB(x, y, rgb+numToAdd);
            }
        }
    }
    
    /**
     * Covert image to black and white.
     */
    public void convertToBlackAndWhite() {
        ColorSpace gray_space = ColorSpace.getInstance(ColorSpace.CS_GRAY);
        ColorConvertOp convert_to_gray_op = new ColorConvertOp(gray_space, null);
        convert_to_gray_op.filter(bufferedImage, bufferedImage);
    }
    
    
    /**
     * Rotates image 90 degrees to the left.
     */
    public void rotateLeft(){
        
        int width = bufferedImage.getWidth();
        int height = bufferedImage.getHeight();
        
        BufferedImage result = new BufferedImage(height, 
                width, bufferedImage.TYPE_INT_BGR);
        
        for (int x = 0; x < width; x ++) {
            for (int y = 0; y < height; y ++) {
                int rgb = bufferedImage.getRGB(x, y);
                result.setRGB(y, x, rgb); 
            }
        }
        
        bufferedImage = result;
        
    }
    
    /**
     * Rotates image 90 degrees to the right.
     */
    public void rotateRight(){
        int width = bufferedImage.getWidth();
        int height = bufferedImage.getHeight();
        
        BufferedImage result = new BufferedImage(height, 
                width, bufferedImage.TYPE_INT_BGR);
        
        for (int x = 0; x < width; x ++) {
            for (int y = 0; y < height; y ++) {
                int rgb = bufferedImage.getRGB(x, y);
                result.setRGB(height-y-1, x, rgb); 
            }
        }
        
        bufferedImage = result;
        
    }
    
    
    /**
     * Rotates image 180 degrees.
     */
    public void rotate180(){
        int width = bufferedImage.getWidth();
        int height = bufferedImage.getHeight();
        
        BufferedImage result = new BufferedImage(width, 
                height, bufferedImage.TYPE_INT_BGR);
        
        for (int x = 0; x < width; x ++) {
            for (int y = 0; y < height; y ++) {
                int rgb = bufferedImage.getRGB(x, y);
                result.setRGB(width-x-1, height-y-1, rgb); 
            }
        }
        
        bufferedImage = result;
        
    }
    
    /**
     * Flips the image horizontally
     */
    public void flipHorizontally(){
        int width = bufferedImage.getWidth();
        int height = bufferedImage.getHeight();
        
        BufferedImage result = new BufferedImage(width, 
                height, bufferedImage.TYPE_INT_BGR);
        
        for (int x = 0; x < width; x ++) {
            for (int y = 0; y < height; y ++) {
                int rgb = bufferedImage.getRGB(x, y);
                result.setRGB(width-x-1, y, rgb); 
            }
        }
        
        bufferedImage = result;
        
    }
    
    /**
     * Flips the image vertically.
     */
    public void flipVertically(){
        int width = bufferedImage.getWidth();
        int height = bufferedImage.getHeight();
        
        BufferedImage result = new BufferedImage(width, 
                height, bufferedImage.TYPE_INT_BGR);
        
        for (int x = 0; x < width; x ++) {
            for (int y = 0; y < height; y ++) {
                int rgb = bufferedImage.getRGB(x, y);
                result.setRGB(x, height-y-1, rgb); 
            }
        }
        
        bufferedImage = result;
        
    }
    
    /**
     * Multiply the image.
     * @param timesToMultiplyVertically
     * @param timesToMultiplyHorizantelly
     */
    public void multiply(int timesToMultiplyVertically,
            int timesToMultiplyHorizantelly){
        multiply(timesToMultiplyVertically,timesToMultiplyHorizantelly,0);
    }
    
    /**
     * Multiply the image and also add color each of the multiplied images.
     * @param timesToMultiplyVertically
     * @param timesToMultiplyHorizantelly
     */
    public void multiply(int timesToMultiplyVertically,
            int timesToMultiplyHorizantelly, int colorToHenhancePerPixel){
        int width = bufferedImage.getWidth();
        int height = bufferedImage.getHeight();
        
        BufferedImage result = new BufferedImage(width*timesToMultiplyVertically, 
                height*timesToMultiplyHorizantelly, bufferedImage.TYPE_INT_BGR);
        
        for (int xx = 0; xx < timesToMultiplyVertically; xx ++) {
            for (int yy = 0; yy < timesToMultiplyHorizantelly; yy ++) {
                for (int x = 0; x < width; x ++) {
                    for (int y = 0; y < height; y ++) {
                        int rgb = bufferedImage.getRGB(x, y);
                        result.setRGB(width*xx+x, height*yy+y, rgb+colorToHenhancePerPixel*(yy+xx));
                       
                    }
                }
            }
        }
        
        bufferedImage = result;
    }
    
    /**
     * Combines the image with another image in an equal presence to both;
     * @param newImagePath - image to combine with
     */
    public void combineWithPicture(String newImagePath){
        combineWithPicture(newImagePath, 2);
    }
    
    
    
    /**
     * Combines the image with another image.
     * jump = 2 means that every two pixels the new image is replaced. 
     * This makes the 2 images equal in presence. If jump=3 than every 3rd
     * pixel is replaced by the new image.
     * As the jump is higher this is how much the new image has less presence.
     * 
     * @param newImagePath
     * @param jump 
     */
    public void combineWithPicture(String newImagePath, int jump){
        try {
            BufferedImage bufferedImage2 = ImageIO.read(new File(newImagePath));
            combineWithPicture(bufferedImage2, jump, null);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
    
    
    public void combineWithPicture(Image image2){
        combineWithPicture(image2.getAsBufferedImage(), 2, null);
    }
    public void combineWithPicture(Image image2, int jump){
            combineWithPicture(image2.getAsBufferedImage(), jump, null);
    }
    
    public void combineWithPicture(Image image2, Color ignoreColor){
        combineWithPicture(image2.getAsBufferedImage(), 2, ignoreColor);
    }
    public void combineWithPicture(Image image2, int jump, Color ignoreColor){
            combineWithPicture(image2.getAsBufferedImage(), jump, ignoreColor);
    }
    
    /**
     * Combines the image with another image.
     * jump = 2 means that every two pixels the new image is replaced. 
     * This makes the 2 images equal in presence. If jump=3 than every 3rd
     * pixel is replaced by the new image.
     * As the jump is higher this is how much the new image has less presence.
     *  
     * ignoreColor is a color in the new image that will not be copied - 
     * this is good where there is a background which you do not want to copy.
     *  
     * @param bufferedImage2
     * @param jump
     * @param ignoreColor
     */
    private void combineWithPicture(BufferedImage bufferedImage2, 
            int jump, Color ignoreColor){
        checkJump(jump);
        
        int width = bufferedImage.getWidth();
        int height = bufferedImage.getHeight();
        
        int width2 = bufferedImage2.getWidth();
        int height2 = bufferedImage2.getHeight();
        
        int ignoreColorRgb = -1;
        
        if(ignoreColor != null){
            ignoreColorRgb = ignoreColor.getRGB();
        }
        
        for (int y = 0; y < height; y ++) {
            for (int x = y%jump; x < width; x +=jump) {
                if(x >= width2 || y>= height2){
                    continue; 
                }
                
                int rgb = bufferedImage2.getRGB(x, y);
                
                if( rgb != ignoreColorRgb ){
                    bufferedImage.setRGB(x, y, rgb);
                }
            }
        }
        
    }
    
    
    public void crop(int startX, int startY, int endX, int endY){
        int width = bufferedImage.getWidth();
        int height = bufferedImage.getHeight();
        
        if(startX == -1){
            startX = 0;
        }
        
        if(startY == -1){
            startY = 0;
        }
        
        if(endX == -1){
            endX = width-1;
        }
        
        if(endY == -1){
            endY = height-1;
        }
        
        BufferedImage result = new BufferedImage(endX-startX+1, 
                endY-startY+1, bufferedImage.TYPE_INT_BGR);
        
        for (int y = startY; y < endY; y ++) {
            for (int x = startX; x < endX; x ++) {
                int rgb = bufferedImage.getRGB(x, y);
                result.setRGB(x-startX, y-startY, rgb); 
            }
        }
        bufferedImage = result;
    }
    
    private void saveImage(File file) {
        try {
            ImageIO.write(bufferedImage, getFileType(file), file);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    public void emphasize(int startX, int startY, int endX, int endY){
        emphasize(startX, startY, endX, endY, Color.BLACK, 3 );
    }
    
    public void emphasize(int startX, int startY, int endX, int endY, Color backgroundColor){
        emphasize(startX, startY, endX, endY, backgroundColor, 3 );
    }
    
    public void emphasize(int startX, int startY, int endX, int endY,int jump){
        emphasize(startX, startY, endX, endY, Color.BLACK, jump );
    }
    public void emphasize(int startX, int startY, int endX, int endY, Color backgroundColor,int jump){
        
        checkJump(jump);
        
        int width = bufferedImage.getWidth();
        int height = bufferedImage.getHeight();
        
        if(startX == -1){
            startX = 0;
        }
        
        if(startY == -1){
            startY = 0;
        }
        
        if(endX == -1){
            endX = width-1;
        }
        
        if(endY == -1){
            endY = height-1;
        }
        
        
        for (int y = 0; y < height; y ++) {
            for (int x = y%jump; x < width; x +=jump) {
                
                if(y >= startY && y <= endY && x >= startX && x <= endX){
                    continue;
                }
                
                bufferedImage.setRGB(x, y, backgroundColor.getRGB()); 
            }
        }
       
    }
    
    private void checkJump(int jump) {
        if(jump<1){
            throw new RuntimeException("Error: jump can not be less than 1");
        }
        
    }

    public void addColorToImage(Color color, int jump){
        addColorToImage(color.getRGB(),jump);
    }
    
    public void addColorToImage(int rgb, int jump){
        checkJump(jump);
        
        int width = bufferedImage.getWidth();
        int height = bufferedImage.getHeight();
        
        for (int y = 0; y < height; y ++) {
            for (int x = y%jump; x < width; x +=jump) {
                bufferedImage.setRGB(x, y, rgb); 
            }
        }
    }
    
    
    
    public void affineTransform (double fShxFactor, double fShyFactor) {

        try {
          AffineTransform shearer =
            AffineTransform.getShearInstance (fShxFactor, fShyFactor);
          AffineTransformOp shear_op =
            new AffineTransformOp (shearer, null);
          bufferedImage = shear_op.filter (bufferedImage, null);
        }
        catch (Exception e) {
          System.out.println("Shearing exception = " + e);
        }
      } 
    
    private String getFileType(File file) {
        String fileName = file.getName();
        int idx =  fileName.lastIndexOf(".");
        if(idx == -1){
            throw new RuntimeException("Invalid file name");
        }
        
        return fileName.substring(idx+1);
    }
    
    
    public int getWidth(){
        return bufferedImage.getWidth();
    }
    
    public int getHeight(){
        return bufferedImage.getHeight();
    }
    
    public static void main(String[] args) {
        /*
        Image image  = new Image("c:/pics/p1.jpg");
        image.resize(10);
        image.multiply(5, 5, 11111);
        image.saveAs("c:/pics/multiply+color.jpg");
        */
        /*
        Image image  = new Image("c:/pics/israel_flag.gif");
        Image image2  = new Image("c:/pics/palestine_flag.gif");
        //image.resize(50);
        //image2.resize(50);
        //image.affineTransform(0, 0.3);
        //image2.affineTransform(0, -0.3);
        image.combineWithPicture(image2);
        image.saveAs("c:/pics/affineTransformAndCombine2.jpg");
       */
       /*
        Image image  = new Image("c:/pics/p1.jpg");
        image.resize(50);
        image.affineTransform(0.0, 0.5);
        image.saveAs("c:/pics/affineTransform.jpg");
        */
     /*
        Image image  = new Image("c:/pics/heart.gif");
        image.multiply(20, 20);
        Image image2  = new Image("c:/pics/p6.jpg");
        image2.crop(800, 0, -1, -1);
        image2.resize(50);
        image2.combineWithPicture(image,3,Color.white);
        image2.saveAs("c:/pics/combineWithPictureWithoutBackground.jpg");
        /*
        image.resize(5);
        image.multiply(20, 20);
        image.combineWithPicture("c:/p2.jpg");
        //image.addColorToImage(Color.yellow, 3);
        //image.addColorToImage(Color.red, 5);
        //image.combineWithPicture("c:/p2.jpg",3);
      
      */
        
        Image image  = new Image("c:/pics/p1.jpg");
        int width = image.getWidth();
        int height = image.getHeight();
        for(int i=0,c=0;i<height;c++,i+=50){
            int x = width/2  - i;
            int y = height/2 - i;
            
            image.emphasize(x, y, width-1-x, height-1-y, Color.BLACK, 12 - c/4);
        }
        image.saveAs("c:/pics/emphesizeTrick.jpg");
      //  */
       // image.saveAs("c:/xxx.jpg");
        /*
        Image image  = new Image("c:/pics/p1.jpg");
        image.addColorToImage(Color.red, 5);
        image.saveAs("c:/pics/addColorToImage.jpg");
        */
    }
}


分享到:
评论

相关推荐

    C#图片操作类

    C#图片操作类,可生成缩略图,添加水印等

    c#图片操作函数大全

    c#图片操作函数大全,包括图片缩放,缩略图、截取,下载等等

    C# winform 图片操作控件,鼠标操作,导入图片,可缩放、旋转、移动

    总的来说,C# WinForm图片操作控件是通过事件驱动、图像处理和UI交互设计相结合来实现的,为用户提供直观且灵活的图片操作体验。通过学习和理解这种控件的工作原理,开发者可以更好地掌握WinForm应用中的图像处理...

    Android-强大的图片操作库

    在Android开发中,图片操作是不可或缺的一部分,无论是加载网络图片,还是进行图片处理,都需要借助特定的库来实现。本文将深入探讨一个强大的Android图片操作库,并基于提供的压缩包文件"Liberuman-ImageSet-d...

    C#实现的图片操作封装类

    在C#编程环境中,开发一个图片操作封装类可以极大地提高代码的可复用性和效率。这类封装通常包含多个核心功能,如添加水印、图片压缩和尺寸调整,这些都是日常开发中处理图像时常见的需求。 首先,`ImageClass.cs`...

    几个JS图片操作工具

    在JavaScript的世界里,图片操作是一项常见的任务,无论是前端展示还是后端处理,都有可能涉及到。这篇博客“几个JS图片操作工具”(博文链接:https://dreamit.iteye.com/blog/231712)为我们揭示了一些实用的...

    myimg.fll--图片操作

    在IT行业中,图片操作是一项常见的任务,特别是在图形用户界面(GUI)开发、图像处理和数据分析等领域。本篇文章将深入探讨“myimg.fll”这个压缩包文件所涉及的图片操作,包括图片裁剪、缩放、打开以及gif文件操作...

    VC JPG图片操作源码

    在这个"VC JPG图片操作源码"中,我们可以学习到如何使用VC++来实现对JPG图片的基本操作,例如放大、缩小和拖动。 首先,VC++项目通常会使用MFC(Microsoft Foundation Classes)库,它提供了一套面向对象的API,...

    JPG图片操作类

    本篇文章将围绕"JPG图片操作类"这一主题,详细解释在VC6.0环境下如何通过DLL(动态链接库)项目实现JPG图片的各种操作。 首先,DLL(Dynamic Link Library)是一种允许在多个应用程序之间共享代码和资源的机制。在...

    vc操作excel,读写excel,包括图片操作

    vc操作excel,读写excel,包括图片操作.

    jquery图片操作!

    这篇名为"jquery图片操作!"的博文可能详细讲解了如何利用jQuery来处理网页中的图像元素。尽管没有具体的描述,我们可以根据标题推测主要内容可能包括图片的加载、显示、隐藏、尺寸调整、动画效果以及与用户交互等...

    (tree_listview)图片操作,反射

    在这个特定的话题中,我们主要关注的是在`TreeListView`中进行图片操作以及利用反射技术来实现这些操作。下面我们将深入探讨这两个核心概念。 首先,我们来看`TreeListView`中的图片操作。在GUI(图形用户界面)...

    关于图片操作(剪切、缩放)

    在IT领域,图片操作是常见的图像处理任务,尤其在设计、摄影、网页开发以及各种多媒体应用中至关重要。本文将深入探讨“图片操作”,包括图片的剪切和缩放,这两个基本但实用的功能。 图片剪切,又称为图像裁剪,是...

    C#-图片操作

    C#-图片操作(图片缩略、图片生成文字水印、多图片合成、图片缩放)

    FusionChartsV3.2导出图片操作指南

    FusionCharts V3.2 导出图片操作指南 java 版

    Android之WebView仿微信中图片操作(含二维码识别)

    这篇教程将专注于如何在WebView中实现类似微信的图片操作功能,包括长按图片进行操作以及识别图片中的二维码。以下是对这个主题的详细阐述: 首先,我们要在Android应用中集成WebView。在布局XML文件中添加一个...

    图片操作类的使用

    图片操作类的使用

    批量图片操作

    在IT行业中,批量图片操作是一项常见的任务,尤其对于摄影师、设计师以及任何需要处理大量图像的用户来说,这是一项必备技能。标题"批量图片操作"暗示了我们将在讨论一种能够一次性处理多个图片,进行统一调整的方法...

    php图片操作类 php缩放图片 水印添加!

    php图片操作可生成等比例缩略图 和图片水印添加!

    图片上传前预览和操作图片

    "图片上传前预览和操作图片"这个主题涉及的技术点主要包括图片预览、图片操作以及上传流程。下面我们将详细探讨这些知识点。 1. 图片预览: 图片预览功能允许用户在实际上传之前查看选定的图片,确保图片质量、方向...

Global site tag (gtag.js) - Google Analytics