그림에 대한 처리

일부 그림 처리:
 
// 	
 public static void composePic(String filesrc,String logosrc,String outsrc,int x,int y) throws Exception {
		    try {
		        File bgfile = new File(filesrc);
		        Image bg_src = javax.imageio.ImageIO.read(bgfile);
		        
		        File logofile = new File(logosrc);
		        Image logo_src = javax.imageio.ImageIO.read(logofile);
		        
		        int bg_width = bg_src.getWidth(null);
		        int bg_height = bg_src.getHeight(null);
		        int logo_width = logo_src.getWidth(null);;
		        int logo_height = logo_src.getHeight(null);

		        BufferedImage tag = new BufferedImage(bg_width, bg_height, BufferedImage.TYPE_INT_RGB);
		        
		        Graphics2D g2d = tag.createGraphics();
		        g2d.drawImage(bg_src, 0, 0, bg_width, bg_height, null);
		        
		        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP,1.0f)); //   
		        g2d.drawImage(logo_src,x,y,logo_width,logo_height, null);            
		        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); //   
		        
		        FileOutputStream out = new FileOutputStream(outsrc);
		        JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
		        encoder.encode(tag);
		        out.close();
		    }catch (Exception e) {
		        e.printStackTrace();
		        log.info(" :" + e.getMessage());
		        throw new Exception(e);
		    }
		  }
// 
	 public static void createImg(String path, int width, int height) throws Exception{
	     File file = new File(path);
	     BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);   
	        Graphics2D g2 = (Graphics2D)bi.getGraphics();   
	        g2.setBackground(Color.WHITE);   
	        g2.clearRect(0, 0, width, height);   
	        g2.setPaint(Color.RED);   
	        ImageIO.write(bi, "jpg", file);   
	 }

//그림base64 인코딩 및 디코딩
 
public class ImgConvert
{
    public static String getBase64(String path) throws Exception
    {// , Base64 
        InputStream in = null;
        byte[] data = null;
        if(null == path || "".equals(path)) return "";
        // 
        File file = new File(path);
        in = new FileInputStream(file);        
        data = new byte[in.available()];
        in.read(data);
        in.close();
        // Base64 
        BASE64Encoder encoder = new BASE64Encoder();
        return encoder.encode(data);// Base64 
    }
    
    public static boolean getImage(String imgStr, String path)
    {// Base64 
        if (imgStr == null) // 
            return false;
        BASE64Decoder decoder = new BASE64Decoder();
        try 
        {
            //Base64 
            byte[] b = decoder.decodeBuffer(imgStr);
            for(int i=0;i<b.length;++i)
            {
                if(b[i]<0)
                {// 
                    b[i]+=256;
                }
            }
            // jpeg 
            OutputStream out = new FileOutputStream(path);    
            out.write(b);
            out.flush();
            out.close();
            return true;
        } 
        catch (Exception e) 
        {
            return false;
        }
    }
}
 
 
//  
public class ImgMessage {
	public static void main(String[] args) {
		String url = "D:\\Blue.jpg";
	}

	public String writeMessage(String message, String url, int offsetTop, int offsetLeft) {
		try {
			//  
			JPEGImageDecoder decoder = JPEGCodec
					.createJPEGDecoder(new FileInputStream(url)); //  
			BufferedImage image = decoder.decodeAsBufferedImage();
			Graphics2D g = image.createGraphics();//  
			g.setColor(Color.BLACK); //  
			RenderingHints rh = new RenderingHints(
					RenderingHints.KEY_ANTIALIASING,
					RenderingHints.VALUE_ANTIALIAS_ON);
			rh.put(RenderingHints.KEY_STROKE_CONTROL,
					RenderingHints.VALUE_STROKE_PURE);
			rh.put(RenderingHints.KEY_ALPHA_INTERPOLATION,
					RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
			rh.put(RenderingHints.KEY_TEXT_ANTIALIASING,
					RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
			rh.put(RenderingHints.KEY_RENDERING,
					RenderingHints.VALUE_RENDER_QUALITY);
			g.setRenderingHints(rh);
			g.setColor(Color.black);
			Font font = new Font(" ", Font.BOLD, 12);
			g.setFont(font);
			FontMetrics fm = g.getFontMetrics(font);

			//  
			int fontHeight = fm.getHeight();//  
			int rowIndex = 1;
			int left = offsetLeft;
			for (int i = 0; i < message.length(); i++) {
				char c = message.charAt(i);
				int charWidth = fm.charWidth(c); //  
				//  
				if (Character.isISOControl(c)) {
					rowIndex++;
					left = offsetLeft;
				}
				g.drawString(String.valueOf(c), left, offsetTop + rowIndex
						* fontHeight); //  
				left += charWidth; //  
			}
			g.dispose();
		
			String outFileName = url; //  
			FileOutputStream out = new FileOutputStream(outFileName);//  
			JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
			encoder.encode(image);
			out.close();
			return outFileName;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
}

//그림 자르기
 
/**
     *  
     * 
     * @param img
     *             
     * @param dest
     *             
     * @param top
     *             Y
     * @param left
     *             X
     * @param width
     *             
     * @param height
     *             
     * @param type 
     *             
     * @return
     * @throws IOException
     */
    public static void resizeImage(File img, String dest, int top, int left,
            int width, int height, String type) throws Exception {
       try{
           File fileDest = new File(dest);
           BufferedImage bi = (BufferedImage) ImageIO.read(img);
           BufferedImage bi_cropper = bi.getSubimage(left, top, width, height);
           ImageIO.write(bi_cropper, type, fileDest);
       }catch(Exception e){
           e.printStackTrace();
           log.error(" :" + e.getMessage());
           throw new Exception(e.getMessage());
       }
    }
    
    /**
     *  gif 
     * @param img
     * @param dest
     * @param top
     * @param left
     * @param width
     * @param height
     */
    public void resizeGifImage(File img, String dest, int top, int left, int width, int height){
        File des = new File(dest);
        GifImage gif;
        try {
            gif = GifDecoder.decode(img);
            Rectangle rect = new Rectangle(top, left, width, height-3);
            GifImage cropIMG = GifTransformer.crop(gif, rect);
            GifEncoder.encode(cropIMG, des);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

jquery 플러그인:
easydrag:  , div id (top,left), iframe top,left。
jquery.form:  ajax form 。
jcarousel:  。jcrop:  。
kindeditor: , , 。

java는 스플릿("\\|")을 세로선으로 구분합니다.
js replace replace(/,/g, '_') , 。

좋은 웹페이지 즐겨찾기