org.apache.poi.sl.usermodel.PictureData.PictureType Java Examples

The following examples show how to use org.apache.poi.sl.usermodel.PictureData.PictureType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WatermarkPptTests.java    From kbase-doc with Apache License 2.0 6 votes vote down vote up
@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");

       
	}
 
Example #2
Source File: DrawPictureShape.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #3
Source File: PptMapper.java    From PPT-Templates with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #4
Source File: ImagesUtils.java    From PPT-Templates with Apache License 2.0 5 votes vote down vote up
public static PictureType guessPictureType(byte[] pictureData) {
	for(ImageType imageType : ImageType.values()) {
		if(startsWith(pictureData, imageType.startPattern)) {
			return imageType.poiType;
		}
	}

	return null;
}
 
Example #5
Source File: PptMapper.java    From PPT-Templates with Apache License 2.0 3 votes vote down vote up
/**
 * 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
	);
}
 
Example #6
Source File: PptMapper.java    From PPT-Templates with Apache License 2.0 3 votes vote down vote up
/**
 * 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;
}
 
Example #7
Source File: SlideShow.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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;
 
Example #8
Source File: SlideShow.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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;
 
Example #9
Source File: SlideShow.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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;