사용자 도구

사이트 도구


java:image

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
java:image [2011/11/21 17:55]
kwon37xi
java:image [2023/08/09 17:19] (현재)
kwon37xi
줄 1: 줄 1:
 ====== Java Image ====== ====== Java Image ======
   * [[java:image/resize|java:image/resize]]   * [[java:image/resize|java:image/resize]]
 +  * [[java:scrimage|scrimage]]
  
 ===== JAI - Java Advanced Imaging ===== ===== JAI - Java Advanced Imaging =====
 +  * http://java.sun.com/javase/technologies/desktop/media/jai/ 
 +  * [[http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/JAITOC.fm.html|Programming in Java Advanced Imaging]]
   * [[http://www.oracle.com/technetwork/java/current-142188.html|JAI Download]]. 전체 설치를 안하고 다음 두가지만 설치해도 된다.   * [[http://www.oracle.com/technetwork/java/current-142188.html|JAI Download]]. 전체 설치를 안하고 다음 두가지만 설치해도 된다.
     * [[http://mvnrepository.com/artifact/javax.media/jai_core|jai_core]]     * [[http://mvnrepository.com/artifact/javax.media/jai_core|jai_core]]
     * [[http://mvnrepository.com/artifact/com.sun.media/jai_codec|jai_codec]]     * [[http://mvnrepository.com/artifact/com.sun.media/jai_codec|jai_codec]]
-  * 기본적으로 Native Library를 사용하도록 돼 있는데, 아래 설정을 통해 이를 방지한다.<code java>+  * 기본적으로 Native Library를 사용하도록 돼 있는데, 아래 설정을 통해 순수 Java로 사용가능.<code java>
 static { static {
     System.setProperty("com.sun.media.jai.disableMediaLib", "true");     System.setProperty("com.sun.media.jai.disableMediaLib", "true");
 } }
 </code> </code>
 +  * [[http://jaitools.org/|JAITools]]
 ===== Image to BufferedImage ===== ===== Image to BufferedImage =====
 Image 객체를 BufferedImage 객체로 변환하는 방법 Image 객체를 BufferedImage 객체로 변환하는 방법
   * [[http://www.exampledepot.com/egs/java.awt.image/Image2Buf.html|Creating a Buffered Image from an Image]]   * [[http://www.exampledepot.com/egs/java.awt.image/Image2Buf.html|Creating a Buffered Image from an Image]]
   * [[http://www.exampledepot.com/egs/java.awt.image/HasAlpha.html|Determining If an Image Has Transparent Pixels]] : 위 방법에서 사용하는 hasAlpha 메소드 구현   * [[http://www.exampledepot.com/egs/java.awt.image/HasAlpha.html|Determining If an Image Has Transparent Pixels]] : 위 방법에서 사용하는 hasAlpha 메소드 구현
-  * <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; 
-    } 
  
-    // This code ensures that all the pixels in the image are loaded +===== JAI Crop Image ===== 
-    image new ImageIcon(image).getImage();+  * [[http://www.velocityreviews.com/forums/t146186-jai-example-of-cropping.html|JAI example of cropping]] 
 +<code java> 
 +RenderedImage ri JAI.create(“fileload”,pathandfilename);
  
-    // Determine if the image has transparent pixelsfor this method's +public void crop() { 
-    // implementation, see Determining If an Image Has Transparent Pixels +  pb = new ParameterBlock()
-    boolean hasAlpha hasAlpha(image);+  pb.addSource(ri); 
 +  pb.add((float)topLeftmx); 
 +  pb.add((float)topLeftmy); 
 +  pb.add((float)roiWidth); 
 +  pb.add((float)roiHeight); 
 +  ri JAI.create(“crop”,pb); 
 +
 +</code>
  
-    // Create a buffered image with a format that's compatible with the screen +===== imgscalr ===== 
-    BufferedImage bimage null; +  * [[https://github.com/thebuzzmedia/imgscalr|imgscalr – Java Image Scaling Library]]
-    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), image.getHeight(null), transparency); 
-    } catch (HeadlessException e) { 
-        // The system does not have a screen 
-    } 
  
-    if (bimage == null) { +===== Twelvemonkeys ImageIO ===== 
-        // Create a buffered image using the default color model +  * https://github.com/haraldk/TwelveMonkeys : ImageIO extension plugin
-        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 +===== WebP ===== 
-    Graphics g = bimage.createGraphics();+  * [[https://github.com/lonnyj/webp-imageio|webp-imageio]]
  
-    // 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's color model; 
-    // grabbing a single pixel is usually sufficient 
-     PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false); 
-    try { 
-        pg.grabPixels(); 
-    } catch (InterruptedException e) { 
-    } 
- 
-    // Get the image's color model 
-    ColorModel cm = pg.getColorModel(); 
-    return cm.hasAlpha(); 
-} 
-</code> 
java/image.1321865737.txt.gz · 마지막으로 수정됨: 2011/11/21 17:55 저자 kwon37xi