Ignore:
Timestamp:
04/30/11 13:37:01 (9 years ago)
Author:
mlg
Message:

Modifications to try to have a better image quality on resizing

Location:
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/session/SessionManager.java

    r10505 r10698  
    22 
    33import java.io.IOException; 
     4import java.io.InputStream; 
    45import java.io.UnsupportedEncodingException; 
    56 
     
    119120     */ 
    120121    public boolean isProxyError(); 
     122 
     123    /** 
     124     * @param url 
     125     * @return 
     126     * @throws Exception 
     127     */ 
     128    public InputStream getInputStreamFromUrl(String url) throws Exception; 
    121129} 
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/session/impl/SessionManagerImpl.java

    r10505 r10698  
    1717import org.apache.http.client.ClientProtocolException; 
    1818import org.apache.http.client.entity.UrlEncodedFormEntity; 
     19import org.apache.http.client.methods.HttpGet; 
    1920import org.apache.http.client.methods.HttpPost; 
    2021import org.apache.http.conn.params.ConnRoutePNames; 
     
    253254    } 
    254255 
     256    public InputStream getInputStreamFromUrl(String url) throws Exception { 
     257        InputStream content = null; 
     258        HttpGet httpGet = new HttpGet(url); 
     259        HttpResponse response = client.execute(httpGet); 
     260        content = response.getEntity().getContent(); 
     261        return content; 
     262    } 
     263 
    255264    /** 
    256265     * @return the login 
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/util/ImagesUtil.java

    r9893 r10698  
    5151            .getLog(ImagesUtil.class); 
    5252 
     53    private static final GraphicsConfiguration CONFIGURATION = GraphicsEnvironment.getLocalGraphicsEnvironment() 
     54            .getDefaultScreenDevice().getDefaultConfiguration(); 
     55 
     56    public static void main(String[] args) throws IOException { 
     57        scale("/home/mael/Bureau/test.png", "test4.jpg", 1999, 1999); 
     58    } 
     59 
    5360    /** 
    5461     * rotates an image 
     
    101108     */ 
    102109    public static boolean scale(String filePath, String tempName, int width, int height) throws IOException { 
    103         File file = new File(filePath); 
    104110        InputStream imageStream = new BufferedInputStream(new FileInputStream(filePath)); 
    105111        Image image = (Image) ImageIO.read(imageStream); 
     
    117123            width = (int) (height * imageRatio); 
    118124        } 
    119         BufferedImage thumbImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); 
     125        //      BufferedImage thumbImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); 
     126        BufferedImage thumbImage = createCompatibleImage(ImageIO.read(new File(filePath)), width, height); 
    120127        Graphics2D graphics2D = thumbImage.createGraphics(); 
    121128        graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); 
    122129        graphics2D.drawImage(image, 0, 0, width, height, null); 
    123  
     130        graphics2D.dispose(); 
    124131        //      ImageIO.write(thumbImage, "jpg", new FileOutputStream(System.getProperty("java.io.tmpdir") + "/" + tempName)); 
    125132        saveImage(System.getProperty("java.io.tmpdir") + "/" + tempName, thumbImage); 
    126133        return true; 
    127134 
     135    } 
     136 
     137    public static BufferedImage createCompatibleImage(BufferedImage image, int width, int height) { 
     138        return CONFIGURATION.createCompatibleImage(width, height, image.getTransparency()); 
    128139    } 
    129140 
Note: See TracChangeset for help on using the changeset viewer.