diff src/java/de/intevation/mxd/reader/PictureLineSymbolReader.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/PictureLineSymbolReader.java	Fri Aug 12 09:15:34 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/PictureLineSymbolReader.java	Fri Aug 12 16:08:57 2011 +0200
@@ -33,7 +33,12 @@
 
 import org.w3c.dom.Element;
 import java.io.IOException;
+import java.awt.image.BufferedImage;
+import java.awt.image.DataBufferByte;
+import javax.imageio.ImageIO;
+import java.io.ByteArrayOutputStream;
 
+import org.apache.commons.codec.binary.Base64;
 /**
  * Reads picture line symbol information.
  *
@@ -95,29 +100,6 @@
         }
 
         try {
-            if(symbol.getColor() instanceof IRgbColor) {
-                IRgbColor color = (IRgbColor)symbol.getColor();
-                Color c = new Color (
-                    color.getRed(),
-                    color.getGreen(),
-                    color.getBlue());
-                symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
-            }
-            else {
-                RgbColor col = new RgbColor();
-                col.setRGB(symbol.getColor().getRGB());
-                Color c = new Color (
-                    col.getRed(),
-                    col.getGreen(),
-                    col.getBlue());
-                symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
-            }
-        }
-        catch(IOException ioe) {
-            logger.warn("Could not read color.");
-        }
-
-        try {
             symbolElement.setAttribute(
                 "offset",
                 String.valueOf(symbol.getOffset()));
@@ -152,7 +134,40 @@
         catch(IOException ioe) {
             logger.warn("Could not read width.");
         }
+        
+        //Read the picture and convert to base64.
+        try {
+            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.");
+        }
         symbolElement.setAttribute("type", "line");
         symbolElement.setAttribute("style", "picture");
 
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)