Lines 19-27
Link Here
|
19 |
|
19 |
|
20 |
package org.apache.poi.xslf.usermodel; |
20 |
package org.apache.poi.xslf.usermodel; |
21 |
|
21 |
|
|
|
22 |
import java.awt.Dimension; |
23 |
import java.awt.image.BufferedImage; |
22 |
import java.io.IOException; |
24 |
import java.io.IOException; |
23 |
import java.io.InputStream; |
25 |
import java.io.InputStream; |
24 |
import java.io.OutputStream; |
26 |
import java.io.OutputStream; |
|
|
27 |
import javax.imageio.ImageIO; |
25 |
|
28 |
|
26 |
import org.apache.poi.POIXMLDocumentPart; |
29 |
import org.apache.poi.POIXMLDocumentPart; |
27 |
import org.apache.poi.POIXMLException; |
30 |
import org.apache.poi.POIXMLException; |
Lines 37-42
import org.apache.poi.util.IOUtils;
Link Here
|
37 |
@Beta |
40 |
@Beta |
38 |
public final class XSLFPictureData extends POIXMLDocumentPart implements PictureData { |
41 |
public final class XSLFPictureData extends POIXMLDocumentPart implements PictureData { |
39 |
private Long checksum = null; |
42 |
private Long checksum = null; |
|
|
43 |
|
44 |
// original image dimensions (for formats supported by BufferedImage) |
45 |
private Dimension _origSize = null; |
40 |
private int index = -1; |
46 |
private int index = -1; |
41 |
|
47 |
|
42 |
/** |
48 |
/** |
Lines 115-120
public final class XSLFPictureData extends POIXMLDocumentPart implements Picture
Link Here
|
115 |
} |
121 |
} |
116 |
|
122 |
|
117 |
/** |
123 |
/** |
|
|
124 |
* Return the original image dimensions |
125 |
* (for formats supported by BufferedImage). |
126 |
* |
127 |
* Will return a Dimension with zero width/height if the format unsupported. |
128 |
*/ |
129 |
public Dimension getImageDimension() |
130 |
{ |
131 |
if (_origSize == null) |
132 |
{ |
133 |
try |
134 |
{ |
135 |
BufferedImage img = ImageIO.read(getInputStream()); |
136 |
_origSize = new Dimension(img.getWidth(), img.getHeight()); |
137 |
} |
138 |
catch (Exception failed) |
139 |
{ |
140 |
// failed to get information, set as zero size |
141 |
_origSize = new Dimension(); |
142 |
} |
143 |
} |
144 |
|
145 |
return _origSize; |
146 |
} |
147 |
|
148 |
|
149 |
/** |
118 |
* *PictureData objects store the actual content in the part directly without keeping a |
150 |
* *PictureData objects store the actual content in the part directly without keeping a |
119 |
* copy like all others therefore we need to handle them differently. |
151 |
* copy like all others therefore we need to handle them differently. |
120 |
*/ |
152 |
*/ |
Lines 134-139
public final class XSLFPictureData extends POIXMLDocumentPart implements Picture
Link Here
|
134 |
os.close(); |
166 |
os.close(); |
135 |
// recalculate now since we already have the data bytes available anyhow |
167 |
// recalculate now since we already have the data bytes available anyhow |
136 |
checksum = IOUtils.calculateChecksum(data); |
168 |
checksum = IOUtils.calculateChecksum(data); |
|
|
169 |
|
170 |
_origSize = null; // need to recalculate image size |
137 |
} |
171 |
} |
138 |
|
172 |
|
139 |
@Override |
173 |
@Override |