svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.lib / org.gvsig.expressionevaluator.lib.impl / src / main / java / org / gvsig / expressionevaluator / impl / function / image / ImageReadFunction.java @ 44198
History | View | Annotate | Download (1.93 KB)
1 | 44126 | jjdelcerro | package org.gvsig.expressionevaluator.impl.function.image; |
---|---|---|---|
2 | 43512 | jjdelcerro | |
3 | 44126 | jjdelcerro | import java.awt.Graphics2D; |
4 | import java.awt.Image; |
||
5 | import java.awt.RenderingHints; |
||
6 | import java.awt.geom.AffineTransform; |
||
7 | import java.awt.image.BufferedImage; |
||
8 | import java.io.ByteArrayInputStream; |
||
9 | import java.io.File; |
||
10 | import java.io.IOException; |
||
11 | import java.net.URL; |
||
12 | import javax.imageio.ImageIO; |
||
13 | import org.apache.commons.codec.DecoderException; |
||
14 | import org.apache.commons.codec.binary.Base64; |
||
15 | import org.apache.commons.codec.binary.Hex; |
||
16 | 43512 | jjdelcerro | import org.apache.commons.lang3.Range; |
17 | 43521 | jjdelcerro | import org.gvsig.expressionevaluator.Interpreter; |
18 | 43512 | jjdelcerro | import org.gvsig.expressionevaluator.spi.AbstractFunction; |
19 | |||
20 | 44126 | jjdelcerro | public class ImageReadFunction extends AbstractFunction { |
21 | 43512 | jjdelcerro | |
22 | 44126 | jjdelcerro | public ImageReadFunction() {
|
23 | 43512 | jjdelcerro | super(
|
24 | 44126 | jjdelcerro | "Image", "IMAGEREAD", Range.is(1), |
25 | "Read an image from a data source and return it as a 'Java BufferedImage' object.\n"
|
||
26 | + "The data source of the image can be:\n<ul>"
|
||
27 | + "<li>A byte array</li>"
|
||
28 | + "<li>A URL</li>"
|
||
29 | + "<li>A FILE</li>"
|
||
30 | + "<li>A hexadecimal coded string</li>"
|
||
31 | + "<li>A base64 coded string</li>"
|
||
32 | + "</ul>",
|
||
33 | "IMAGEREAD({{source}})",
|
||
34 | new String[]{ |
||
35 | "Value from which to load the image"
|
||
36 | }, |
||
37 | "BufferedImage",
|
||
38 | false
|
||
39 | 43512 | jjdelcerro | ); |
40 | } |
||
41 | |||
42 | @Override
|
||
43 | 44009 | jjdelcerro | public boolean allowConstantFolding() { |
44 | return true; |
||
45 | } |
||
46 | 44126 | jjdelcerro | |
47 | 44009 | jjdelcerro | @Override
|
48 | 43521 | jjdelcerro | public Object call(Interpreter interpreter, Object[] args) { |
49 | 44126 | jjdelcerro | Object arg0 = this.getObject(args, 0); |
50 | SimpleImage image = ImageReadFunction.createSimpleImage(arg0); |
||
51 | if( image.isEmpty() ) {
|
||
52 | return null; |
||
53 | } |
||
54 | return image.getBufferedImage();
|
||
55 | 43512 | jjdelcerro | } |
56 | |||
57 | 44126 | jjdelcerro | public static SimpleImage createSimpleImage(Object source) { |
58 | SimpleImage image = new SimpleImage(source);
|
||
59 | return image;
|
||
60 | } |
||
61 | 43512 | jjdelcerro | } |