Java源码示例:org.apache.poi.sl.usermodel.PictureData.PictureType
示例1
@Test
public void test1() throws IOException {
// create a ppt
XMLSlideShow ppt = new XMLSlideShow(new FileInputStream("E:\\ConvertTester\\ppt\\看看addThread方法的源码.pptx"));
XSLFPictureData pd = ppt.addPicture(new File("E:\\ConvertTester\\images\\jshrss-logo.png"), PictureType.PNG);
for (int i=0;i<ppt.getSlideMasters().size();i++) {
XSLFSlideMaster slideMaster = ppt.getSlideMasters().get(i);
XSLFSlideLayout[] slideLayouts = slideMaster.getSlideLayouts();
for (XSLFSlideLayout slidelayout : slideLayouts) {
XSLFPictureShape ps = slidelayout.createPicture(pd);
ps.setAnchor(new Rectangle2D.Double(20, 20, 640, 400));
}
}
FileOutputStream fos = new FileOutputStream("E:\\ConvertTester\\ppt\\bla.pptx");
ppt.write(fos);
fos.close();
// XSLFSlide sl = ppt.createSlide(slidelayout);
// ((XSLFAutoShape)sl.getShapes().get(0)).setText("title");
// ((XSLFAutoShape)sl.getShapes().get(1)).setText("content");
}
示例2
/**
* Returns an ImageRenderer for the PictureData
*
* @param graphics
* @return the image renderer
*/
public static ImageRenderer getImageRenderer(Graphics2D graphics, String contentType) {
ImageRenderer renderer = (ImageRenderer)graphics.getRenderingHint(Drawable.IMAGE_RENDERER);
if (renderer != null) {
return renderer;
}
if (PictureType.WMF.contentType.equals(contentType)) {
try {
@SuppressWarnings("unchecked")
Class<? extends ImageRenderer> irc = (Class<? extends ImageRenderer>)
Thread.currentThread().getContextClassLoader().loadClass(WMF_IMAGE_RENDERER);
return irc.newInstance();
} catch (Exception e) {
// WMF image renderer is not on the classpath, continuing with BitmapRenderer
// although this doesn't make much sense ...
LOG.log(POILogger.ERROR, "WMF image renderer is not on the classpath - include poi-scratchpad jar!", e);
}
}
return new BitmapImageRenderer();
}
示例3
/**
* Replace an image placeholder by an other image.
* This image placeholder is identified with a link placed on it.
* To fit the placeholder, the replacement mode will be used to
* resize the image.
*
* @param variableName The variable name.
* It should be in the form of <code>$/variableName:argument/</code> in the PPT presentation
* @param imageData The raw data of the image that will replace the placeholder
* @param replacementMode Define how the image should be resized, see {@link PptImageReplacementMode}
* @return The mapper instance
*/
public PptMapper image(String variableName, byte[] imageData,
PptImageReplacementMode replacementMode) {
PictureType imageFormat = ImagesUtils.guessPictureType(imageData);
if(imageFormat == null) {
throw new IllegalArgumentException(
"Enable to determine the image type, "
+ "you may want to directly specify the image type using: "
+ "image(String variableName, byte[] imageData, "
+ "PptImageReplacementMode replacementMode, PictureType imageFormat)"
);
}
return image(variableName, imageData, replacementMode, imageFormat);
}
示例4
public static PictureType guessPictureType(byte[] pictureData) {
for(ImageType imageType : ImageType.values()) {
if(startsWith(pictureData, imageType.startPattern)) {
return imageType.poiType;
}
}
return null;
}
示例5
/**
* Replace an image placeholder by an other image.
* This image placeholder is identified with a link placed on it.
* To fit the placeholder, the replacement mode will be used to
* resize the image.
*
* @param variableName The variable name.
* It should be in the form of <code>$/variableName:argument/</code> in the PPT presentation
* @param imageData The raw data of the image that will replace the placeholder
* @param replacementMode Define how the image should be resized, see {@link PptImageReplacementMode}
* @param imageFormat specify the picture format that will be used in the PPT ;
* note that this format may differ from the original format of the replacement image
* @return The mapper instance
*/
public PptMapper image(String variableName, byte[] imageData,
PptImageReplacementMode replacementMode, PictureType imageFormat) {
return image(
variableName,
imageData,
replacementMode,
imageFormat,
PptImageMapper.DEFAULT_QUALITY_FACTOR,
PptImageMapper.DEFAULT_QUALITY_MULTIPLICATOR
);
}
示例6
/**
* Replace an image placeholder by an other image.
* This image placeholder is identified with a link placed on it.
* To fit the placeholder, the replacement mode will be used to
* resize the image.
*
* @param variableName The variable name.
* It should be in the form of <code>$/variableName:argument/</code> in the PPT presentation
* @param imageData The raw data of the image that will replace the placeholder
* @param replacementMode Define how the image should be resized, see {@link PptImageReplacementMode}
* @param imageFormat specify the picture format that will be used in the PPT ;
* note that this format may differ from the original format of the replacement image
* @param qualityFactor The target picture quality between 0 (low quality) and 1 (high quality)
* @param qualityMultiplicator Another picture quality parameter between 0 (the image will not be shown),
* 1 (the image will be sized to fit exactly its placeholder), N (the image will be resized to fit its placeholder size times N)
* @return The mapper instance
*/
public PptMapper image(String variableName, byte[] imageData,
PptImageReplacementMode replacementMode, PictureType imageFormat,
float qualityFactor,
double qualityMultiplicator) {
imageMapping.put(
variableName,
PptImageMapper.of(imageFormat, replacementMode, imageData, qualityFactor, qualityMultiplicator)
);
return this;
}
示例7
/**
* Adds a picture to the presentation.
*
* @param pictureData The bytes of the picture
* @param format The format of the picture.
*
* @return the picture data reference.
*/
PictureData addPicture(byte[] pictureData, PictureType format) throws IOException;
示例8
/**
* Adds a picture to the presentation.
*
* @param is The stream to read the image from
* @param format The format of the picture.
*
* @return the picture data reference.
* @since 3.15 beta 1
*/
PictureData addPicture(InputStream is, PictureType format) throws IOException;
示例9
/**
* Adds a picture to the presentation.
*
* @param pict The file containing the image to add
* @param format The format of the picture.
*
* @return the picture data reference
* @since 3.15 beta 1
*/
PictureData addPicture(File pict, PictureType format) throws IOException;