Revision 2017 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/DefaultSimpleImage.java
DefaultSimpleImage.java | ||
---|---|---|
7 | 7 |
import java.awt.geom.AffineTransform; |
8 | 8 |
import java.awt.image.BufferedImage; |
9 | 9 |
import java.io.ByteArrayInputStream; |
10 |
import java.io.ByteArrayOutputStream; |
|
10 | 11 |
import java.io.File; |
11 | 12 |
import java.io.FileInputStream; |
12 | 13 |
import java.io.IOException; |
13 | 14 |
import java.io.InputStream; |
14 | 15 |
import java.net.URL; |
16 |
import java.util.logging.Level; |
|
17 |
import java.util.logging.Logger; |
|
15 | 18 |
import javax.imageio.ImageIO; |
16 | 19 |
import javax.swing.ImageIcon; |
17 | 20 |
import org.apache.commons.codec.DecoderException; |
... | ... | |
225 | 228 |
return new DefaultSimpleImage(newImage); |
226 | 229 |
} |
227 | 230 |
|
231 |
private String bytearray_hex(byte[] data) { |
|
232 |
StringBuilder builder = new StringBuilder(); |
|
233 |
for (byte abyte : data) { |
|
234 |
int v = abyte & 0xff; |
|
235 |
builder.append(String.format("%02x", v)); |
|
236 |
} |
|
237 |
return builder.toString(); |
|
238 |
} |
|
239 |
|
|
240 |
@Override |
|
241 |
public byte[] toBytearray() { |
|
242 |
try { |
|
243 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
244 |
ImageIO.write( this.image, "png", baos ); |
|
245 |
baos.flush(); |
|
246 |
byte[] imageInByte = baos.toByteArray(); |
|
247 |
baos.close(); |
|
248 |
return imageInByte; |
|
249 |
} catch (IOException ex) { |
|
250 |
return null; |
|
251 |
} |
|
252 |
} |
|
253 |
|
|
254 |
@Override |
|
255 |
public String toString() { |
|
256 |
byte[] data = this.toBytearray(); |
|
257 |
return bytearray_hex(data); |
|
258 |
} |
|
228 | 259 |
} |
Also available in: Unified diff