comparison 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
comparison
equal deleted inserted replaced
250:d10fd4de02aa 251:6b80e46b8f38
31 import com.esri.arcgis.display.IRgbColor; 31 import com.esri.arcgis.display.IRgbColor;
32 import com.esri.arcgis.display.RgbColor; 32 import com.esri.arcgis.display.RgbColor;
33 33
34 import org.w3c.dom.Element; 34 import org.w3c.dom.Element;
35 import java.io.IOException; 35 import java.io.IOException;
36 import java.awt.image.BufferedImage;
37 import java.awt.image.DataBufferByte;
38 import javax.imageio.ImageIO;
39 import java.io.ByteArrayOutputStream;
36 40
41 import org.apache.commons.codec.binary.Base64;
37 /** 42 /**
38 * Reads picture line symbol information. 43 * Reads picture line symbol information.
39 * 44 *
40 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> 45 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
41 */ 46 */
93 logger.warn("Could not read name. Setting name to \"default\""); 98 logger.warn("Could not read name. Setting name to \"default\"");
94 symbolElement.setAttribute("name", "default"); 99 symbolElement.setAttribute("name", "default");
95 } 100 }
96 101
97 try { 102 try {
98 if(symbol.getColor() instanceof IRgbColor) {
99 IRgbColor color = (IRgbColor)symbol.getColor();
100 Color c = new Color (
101 color.getRed(),
102 color.getGreen(),
103 color.getBlue());
104 symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
105 }
106 else {
107 RgbColor col = new RgbColor();
108 col.setRGB(symbol.getColor().getRGB());
109 Color c = new Color (
110 col.getRed(),
111 col.getGreen(),
112 col.getBlue());
113 symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
114 }
115 }
116 catch(IOException ioe) {
117 logger.warn("Could not read color.");
118 }
119
120 try {
121 symbolElement.setAttribute( 103 symbolElement.setAttribute(
122 "offset", 104 "offset",
123 String.valueOf(symbol.getOffset())); 105 String.valueOf(symbol.getOffset()));
124 } 106 }
125 catch(IOException ioe) { 107 catch(IOException ioe) {
150 String.valueOf(symbol.getWidth())); 132 String.valueOf(symbol.getWidth()));
151 } 133 }
152 catch(IOException ioe) { 134 catch(IOException ioe) {
153 logger.warn("Could not read width."); 135 logger.warn("Could not read width.");
154 } 136 }
137
138 //Read the picture and convert to base64.
139 try {
140 Picture p = symbol.getPicture();
141 Image i = p.toImage();
142 if(i instanceof BufferedImage) {
143 BufferedImage bi = (BufferedImage)i;
144 ByteArrayOutputStream baos = new ByteArrayOutputStream();
145 //Get byte array from image.
146 ImageIO.write(bi, "BMP", baos);
147 Base64 encoder = new Base64();
148 //encode in a base64 string
149 String pict = encoder.encodeBase64String(baos.toByteArray());
150 symbolElement.setAttribute("picture", pict);
155 151
152 //Get transparent color.
153 RgbColor c = new RgbColor();
154 c.setRGB(symbol.getBitmapTransparencyColor().getRGB());
155 Color transp = new Color (
156 c.getRed(),
157 c.getGreen(),
158 c.getBlue());
159 symbolElement.setAttribute(
160 "transparent_color",
161 String.valueOf(transp.getRGB()));
162 }
163 else {
164 logger.warn("Could not read image symbol.");
165 return null;
166 }
167 }
168 catch(IOException ioe) {
169 logger.warn("Could not read picture.");
170 }
156 symbolElement.setAttribute("type", "line"); 171 symbolElement.setAttribute("type", "line");
157 symbolElement.setAttribute("style", "picture"); 172 symbolElement.setAttribute("style", "picture");
158 173
159 return symbolElement; 174 return symbolElement;
160 } 175 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)