문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
java:image [2011/11/21 17:55] kwon37xi |
java:image [2023/08/09 17:19] (현재) kwon37xi |
||
---|---|---|---|
줄 1: | 줄 1: | ||
====== Java Image ====== | ====== Java Image ====== | ||
* [[java: | * [[java: | ||
+ | * [[java: | ||
===== 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(" | ||
} | } | ||
</ | </ | ||
+ | * [[http:// | ||
===== Image to BufferedImage ===== | ===== Image to BufferedImage ===== | ||
Image 객체를 BufferedImage 객체로 변환하는 방법 | Image 객체를 BufferedImage 객체로 변환하는 방법 | ||
* [[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, | + | pb = new ParameterBlock(); |
- | | + | |
+ | | ||
+ | pb.add((float)topLeftmy); | ||
+ | pb.add((float)roiWidth); | ||
+ | pb.add((float)roiHeight); | ||
+ | ri = JAI.create(“crop”, | ||
+ | } | ||
+ | </ | ||
- | // Create a buffered image with a format that's compatible with the screen | + | ===== imgscalr ===== |
- | BufferedImage bimage | + | * [[https://github.com/ |
- | GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); | + | |
- | 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(); | ||
- | GraphicsConfiguration gc = gs.getDefaultConfiguration(); | ||
- | bimage = gc.createCompatibleImage( | ||
- | image.getWidth(null), | ||
- | } catch (HeadlessException e) { | ||
- | // The system does not have a screen | ||
- | } | ||
- | if (bimage | + | ===== Twelvemonkeys ImageIO ===== |
- | // Create a buffered image using the default color model | + | * https://github.com/ |
- | int type = BufferedImage.TYPE_INT_RGB; | + | |
- | if (hasAlpha) { | + | |
- | type = BufferedImage.TYPE_INT_ARGB; | + | |
- | } | + | |
- | bimage = new BufferedImage(image.getWidth(null), | + | |
- | } | + | |
- | | + | ===== WebP ===== |
- | Graphics g = bimage.createGraphics(); | + | * [[https://github.com/ |
- | // Paint the image onto the buffered image | ||
- | g.drawImage(image, | ||
- | 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(); | ||
- | } | ||
- | </ |