Search Results for '개발노트'

181 POSTS

  1. 2007.11.02 Thumbnamil 이미지 만들기
  2. 2007.11.01 java의 Checked Exception vs UnChecked Exception...
  3. 2007.10.30 prototype.js api 한글

Thumbnamil 이미지 만들기

Posted 2007. 11. 2. 21:53

Thumbnail이미지는 jdk에도 포함될 만큼 많이 또 쉽게 구현하여 사용할수 있다.
그래서...

=========================== TestThumnamil.java ===========================
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

public class TestThumbnail
{

    public static final int VERTICAL = 0;
    public static final int HORIZONTAL = 1;

    public static final String IMAGE_JPEG = "jpeg";
    public static final String IMAGE_JPG = "jpg";
    public static final String IMAGE_GIF = "gif";
    public static final String IMAGE_PNG = "png";

    private ImageIcon image;
    private ImageIcon thumb;

    public TestThumbnail()
    {
    }
    /*
    public TestThumbnail(Image image)
    {
     this.image = new ImageIcon(image);
    }
*/
/*
    public TestThumbnail(String fileName)
    {
     image = new ImageIcon(fileName);
    }
    */
    public void setImageFile(String fileName)
    {
     image = new ImageIcon(fileName);
    }

    public Image getThumbnail(int size, int dir)
    {
        if (dir == HORIZONTAL)
        {
            thumb = new ImageIcon(
                image.getImage().getScaledInstance(
                    size, -1, Image.SCALE_SMOOTH)
            );
        }
        else
        {
            thumb = new ImageIcon(
                image.getImage().getScaledInstance(
                    -1, size, Image.SCALE_SMOOTH)
            );
        }
        return thumb.getImage();
    }

    public Image getThumbnail(int size, int dir, int scale)
    {
        if (dir == HORIZONTAL)
        {
            thumb = new ImageIcon(
                image.getImage().getScaledInstance(size, -1, scale)
            );
        }
        else
        {
            thumb = new ImageIcon(
                image.getImage().getScaledInstance(-1, size, scale)
            );
        }
        return thumb.getImage();
    }

    public void saveThumbnail(File file, String imageType)
    {
        if (thumb != null)
        {
            BufferedImage bi = new BufferedImage(
                thumb.getIconWidth(),
                thumb.getIconHeight(),
                BufferedImage.TYPE_INT_RGB
            );
            Graphics g = bi.getGraphics();
            g.drawImage(thumb.getImage(), 0, 0, null);
            try
            {
                ImageIO.write(bi, imageType, file);
            }
            catch (IOException ioe)
            {
                System.out.println("Error occured saving thumbnail");
            }
        }
        else
        {
            System.out.println("Thumbnail has not yet been created");
        }
    }

    public void makeThumbnail(String oriFileName) {

     setImageFile(oriFileName);
     File f = new File(oriFileName);

        getThumbnail(100, TestThumbnail.HORIZONTAL);

        System.out.println(oriFileName.substring(0,oriFileName.indexOf(".")));
        String [] fileArr = oriFileName.split(".");
        //String [] fileArr = oriFileName.split(".");

        System.out.println(oriFileName+","+fileArr.length);
        String imageNamePath  = oriFileName.substring(0,oriFileName.indexOf("."));
        String imageExt = oriFileName.substring(oriFileName.indexOf(".")+1, oriFileName.length());

        String IMG_TYPE = "";
        if(imageExt.equalsIgnoreCase("jpg"))
         IMG_TYPE = TestThumbnail.IMAGE_JPG;
        if(imageExt.equalsIgnoreCase("jpeg"))
         IMG_TYPE = TestThumbnail.IMAGE_JPEG;
        if(imageExt.equalsIgnoreCase("gif"))
         IMG_TYPE = TestThumbnail.IMAGE_GIF;

        saveThumbnail(new File(imageNamePath+"_thumb."+imageExt), IMG_TYPE);

    }

    public static void main(String [] args)
    {
     TestThumbnail ct = new TestThumbnail();

     ct.makeThumbnail("d:/james_start2.jpg");
     /*
     ct.setImageFile("d:/james_start2.jpg");
        ct.getThumbnail(100, TestThumbnail.HORIZONTAL);
        ct.saveThumbnail(new File("d:/james_start2_thumb.jpg"), TestThumbnail.IMAGE_JPEG);
        */
    }

}



checked Ex : java.lang.Exception을 상속받는 모든것... 컴파일시 에러가 발생함
unchecked Ex : RuntimeException... 컴파일시 에러가 나지 않지만 실행중에 에러가 발생함.
 unchecked Exception 이 발생하면 찾기에 참 난감하다... 대표적인 놈이 NullpointerException...
 이놈땜에 대부분의 개발자들이 골머리를 썩는다...

Spring AOP에서 제공하는 트랜잭션은 기본적으로 Unchecked Exception인 경우에만 Rollback을... Checked Exception인 경우에 Commit을 해버린다. Default...


prototype.js api 한글

Posted 2007. 10. 30. 16:08


« PREV : 1 : ··· : 51 : 52 : 53 : 54 : 55 : 56 : 57 : ··· : 61 : NEXT »