[jboss-cvs] jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/util ...
Christian Bauer
christian at hibernate.org
Tue Jun 12 13:51:00 EDT 2007
User: cbauer
Date: 07/06/12 13:51:00
Modified: examples/wiki/src/main/org/jboss/seam/wiki/util
WikiUtil.java
Log:
Pre-generate thumbnails
Revision Changes Path
1.8 +35 -0 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/util/WikiUtil.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: WikiUtil.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/util/WikiUtil.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- WikiUtil.java 12 Jun 2007 12:30:01 -0000 1.7
+++ WikiUtil.java 12 Jun 2007 17:51:00 -0000 1.8
@@ -8,9 +8,15 @@
import javax.faces.component.UIData;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
+import javax.swing.*;
+import javax.imageio.ImageIO;
import java.util.Collection;
import java.util.List;
import java.math.BigDecimal;
+import java.awt.image.BufferedImage;
+import java.awt.*;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
/**
* Adds stuff to and for JSF that should be there but isn't. Also stuff that is exposed
@@ -142,6 +148,35 @@
return sb.toString();
}
+ public static byte[] resizeImage(byte[] imageData, String contentType, int width) {
+ ImageIcon icon = new ImageIcon(imageData);
+
+ double ratio = (double) width / icon.getIconWidth();
+ int resizedHeight = (int) (icon.getIconHeight() * ratio);
+
+ int imageType = "image/png".equals(contentType)
+ ? BufferedImage.TYPE_INT_ARGB
+ : BufferedImage.TYPE_INT_RGB;
+ BufferedImage bImg = new BufferedImage(width, resizedHeight, imageType);
+ Graphics2D g2d = bImg.createGraphics();
+ g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
+ g2d.drawImage(icon.getImage(), 0, 0, width, resizedHeight, null);
+ g2d.dispose();
+
+ String formatName = "";
+ if ("image/png".equals(contentType)) formatName = "png";
+ else if ("image/jpeg".equals(contentType)) formatName = "jpeg";
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
+ try {
+ ImageIO.write(bImg, formatName, baos);
+ return baos.toByteArray();
+ } catch (IOException ex) {
+ throw new RuntimeException(ex);
+ }
+
+ }
+
public static Throwable unwrap(Throwable throwable) throws IllegalArgumentException {
if (throwable == null) {
throw new IllegalArgumentException("Cannot unwrap null throwable");
More information about the jboss-cvs-commits
mailing list