문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 다음 판 양쪽 다음 판 | ||
java:image [2011/11/21 17:55] kwon37xi |
java:image [2011/11/22 10:47] kwon37xi [JAI - Java Advanced Imaging] |
||
---|---|---|---|
줄 3: | 줄 3: | ||
===== JAI - Java Advanced Imaging ===== | ===== JAI - Java Advanced Imaging ===== | ||
+ | * http:// | ||
+ | * [[http:// | ||
* [[http:// | * [[http:// | ||
* [[http:// | * [[http:// | ||
* [[http:// | * [[http:// | ||
- | * 기본적으로 Native Library를 사용하도록 돼 있는데, 아래 설정을 통해 | + | * 기본적으로 Native Library를 사용하도록 돼 있는데, 아래 설정을 통해 |
static { | static { | ||
System.setProperty(" | System.setProperty(" | ||
줄 17: | 줄 18: | ||
* [[http:// | * [[http:// | ||
* [[http:// | * [[http:// | ||
- | * <code java> | ||
- | // This method returns a buffered image with the contents of an image | ||
- | public static BufferedImage toBufferedImage(Image image) { | ||
- | if (image instanceof BufferedImage) { | ||
- | return (BufferedImage)image; | ||
- | } | ||
- | | + | ===== JAI Crop Image ===== |
- | | + | * [[http://www.velocityreviews.com/ |
+ | <code java> | ||
+ | RenderedImage ri = JAI.create(“fileload”, | ||
- | // Determine if the image has transparent pixels; for this method' | + | public void crop() { |
- | // implementation, | + | |
- | boolean hasAlpha = hasAlpha(image); | + | pb.addSource(ri); |
- | + | pb.add((float)topLeftmx); | |
- | // Create a buffered image with a format that's compatible with the screen | + | pb.add((float)topLeftmy); |
- | BufferedImage bimage | + | |
- | GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); | + | pb.add((float)roiHeight); |
- | try { | + | |
- | // Determine the type of transparency of the new buffered image | + | |
- | int transparency = Transparency.OPAQUE; | + | |
- | if (hasAlpha) { | + | |
- | transparency = Transparency.BITMASK; | + | |
- | } | + | |
- | + | ||
- | // Create the buffered image | + | |
- | GraphicsDevice gs = ge.getDefaultScreenDevice(); | + | |
- | | + | |
- | | + | |
- | image.getWidth(null), image.getHeight(null), | + | |
- | } catch (HeadlessException e) { | + | |
- | // The system does not have a screen | + | |
- | } | + | |
- | + | ||
- | if (bimage == null) { | + | |
- | // Create a buffered image using the default color model | + | |
- | int type = BufferedImage.TYPE_INT_RGB; | + | |
- | if (hasAlpha) { | + | |
- | type = BufferedImage.TYPE_INT_ARGB; | + | |
- | } | + | |
- | bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type); | + | |
- | } | + | |
- | + | ||
- | // Copy image to buffered image | + | |
- | Graphics g = bimage.createGraphics(); | + | |
- | + | ||
- | // Paint the image onto the buffered image | + | |
- | g.drawImage(image, 0, 0, null); | + | |
- | g.dispose(); | + | |
- | + | ||
- | return bimage; | + | |
} | } | ||
+ | </ | ||
- | // This method returns true if the specified image has transparent pixels | ||
- | public static boolean hasAlpha(Image image) { | ||
- | // If buffered image, the color model is readily available | ||
- | if (image instanceof BufferedImage) { | ||
- | BufferedImage bimage = (BufferedImage)image; | ||
- | return bimage.getColorModel().hasAlpha(); | ||
- | } | ||
- | |||
- | // Use a pixel grabber to retrieve the image' | ||
- | // grabbing a single pixel is usually sufficient | ||
- | | ||
- | try { | ||
- | pg.grabPixels(); | ||
- | } catch (InterruptedException e) { | ||
- | } | ||
- | |||
- | // Get the image' | ||
- | ColorModel cm = pg.getColorModel(); | ||
- | return cm.hasAlpha(); | ||
- | } | ||
- | </ |