comparison 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
comparison
equal deleted inserted replaced
250:d10fd4de02aa 251:6b80e46b8f38
23 23
24 import com.esri.arcgis.display.ISymbol; 24 import com.esri.arcgis.display.ISymbol;
25 import com.esri.arcgis.display.IMarkerSymbol; 25 import com.esri.arcgis.display.IMarkerSymbol;
26 import com.esri.arcgis.display.PictureMarkerSymbol; 26 import com.esri.arcgis.display.PictureMarkerSymbol;
27 import com.esri.arcgis.carto.PictureElement; 27 import com.esri.arcgis.carto.PictureElement;
28 import com.esri.arcgis.support.ms.stdole.Picture;
29 import com.esri.arcgis.display.RgbColor;
28 30
29 import org.w3c.dom.Element; 31 import org.w3c.dom.Element;
30 import java.io.IOException; 32 import java.io.IOException;
33 import java.awt.Image;
34 import java.awt.image.BufferedImage;
35 import java.awt.image.DataBufferByte;
36 import javax.imageio.ImageIO;
37 import java.io.ByteArrayOutputStream;
38 import java.awt.Color;
39
40 import org.apache.commons.codec.binary.Base64;
31 41
32 /** 42 /**
33 * Reads picture marker symbol information. 43 * Reads picture marker symbol information.
34 * 44 *
35 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> 45 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
126 catch(IOException ioe) { 136 catch(IOException ioe) {
127 logger.warn("Could not read name. Setting name to \"default\""); 137 logger.warn("Could not read name. Setting name to \"default\"");
128 symbolElement.setAttribute("name", "default"); 138 symbolElement.setAttribute("name", "default");
129 } 139 }
130 140
141 //Read the picture and convert to base64.
131 try { 142 try {
132 PictureElement pElem = new PictureElement(); 143 Picture p = symbol.getPicture();
133 pElem.importPicture(symbol.getPicture()); 144 Image i = p.toImage();
145 if(i instanceof BufferedImage) {
146 BufferedImage bi = (BufferedImage)i;
147 ByteArrayOutputStream baos = new ByteArrayOutputStream();
148 //Get byte array from image.
149 ImageIO.write(bi, "BMP", baos);
150 Base64 encoder = new Base64();
151 //encode in a base64 string
152 String pict = encoder.encodeBase64String(baos.toByteArray());
153 symbolElement.setAttribute("picture", pict);
154
155 //Get transparent color.
156 RgbColor c = new RgbColor();
157 c.setRGB(symbol.getBitmapTransparencyColor().getRGB());
158 Color transp = new Color (
159 c.getRed(),
160 c.getGreen(),
161 c.getBlue());
162 symbolElement.setAttribute(
163 "transparent_color",
164 String.valueOf(transp.getRGB()));
165 }
166 else {
167 logger.warn("Could not read image symbol.");
168 return null;
169 }
134 } 170 }
135 catch(IOException ioe) { 171 catch(IOException ioe) {
136 logger.warn("Could not read picture."); 172 logger.warn("Could not read picture.");
137 } 173 }
138 symbolElement.setAttribute("style", "picture"); 174 symbolElement.setAttribute("style", "picture");
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)