diff src/java/de/intevation/mxd/reader/PictureMarkerSymbolReader.java @ 251:6b80e46b8f38

Added picture symbol support to the converter.
author raimund renkert <raimund.renkert@intevation.de>
date Fri, 12 Aug 2011 16:08:57 +0200
parents df4e0946ef02
children 2cb2f26d0d54
line wrap: on
line diff
--- a/src/java/de/intevation/mxd/reader/PictureMarkerSymbolReader.java	Fri Aug 12 09:15:34 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/PictureMarkerSymbolReader.java	Fri Aug 12 16:08:57 2011 +0200
@@ -25,9 +25,19 @@
 import com.esri.arcgis.display.IMarkerSymbol;
 import com.esri.arcgis.display.PictureMarkerSymbol;
 import com.esri.arcgis.carto.PictureElement;
+import com.esri.arcgis.support.ms.stdole.Picture;
+import com.esri.arcgis.display.RgbColor;
 
 import org.w3c.dom.Element;
 import java.io.IOException;
+import java.awt.Image;
+import java.awt.image.BufferedImage;
+import java.awt.image.DataBufferByte;
+import javax.imageio.ImageIO;
+import java.io.ByteArrayOutputStream;
+import java.awt.Color;
+
+import org.apache.commons.codec.binary.Base64;
 
 /**
  * Reads picture marker symbol information.
@@ -128,9 +138,35 @@
             symbolElement.setAttribute("name", "default");
         }
 
+        //Read the picture and convert to base64.
         try {
-            PictureElement pElem = new PictureElement();
-            pElem.importPicture(symbol.getPicture());
+            Picture p = symbol.getPicture();
+            Image i = p.toImage();
+            if(i instanceof BufferedImage) {
+                BufferedImage bi = (BufferedImage)i;
+                ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                //Get byte array from image.
+                ImageIO.write(bi, "BMP", baos);
+                Base64 encoder = new Base64();
+                //encode in a base64 string
+                String pict = encoder.encodeBase64String(baos.toByteArray());
+                symbolElement.setAttribute("picture", pict);
+
+                //Get transparent color.
+                RgbColor c = new RgbColor();
+                c.setRGB(symbol.getBitmapTransparencyColor().getRGB());
+                Color transp = new Color (
+                        c.getRed(),
+                        c.getGreen(),
+                        c.getBlue());
+                symbolElement.setAttribute(
+                    "transparent_color",
+                    String.valueOf(transp.getRGB()));
+            }
+            else {
+                logger.warn("Could not read image symbol.");
+                return null;
+            }
         }
         catch(IOException ioe) {
             logger.warn("Could not read picture.");
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)