org.openxmlformats.schemas.drawingml.x2006.main.CTBlip Java Examples

The following examples show how to use org.openxmlformats.schemas.drawingml.x2006.main.CTBlip. 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: PptTemplates.java    From PPT-Templates with Apache License 2.0 6 votes vote down vote up
/**
 * Replace an image with another while keeping
 * all the properties of the old image: z-index, border, shadow...
 */
private static void replaceImageInPlace(POIXMLDocumentPart containerDocument, ImageToReplace imageToReplace,
		XSLFPictureData newPictureData, Rectangle2D newImageAnchor) {
	RelationPart rp = containerDocument.addRelation(null, XSLFRelation.IMAGES, newPictureData);
	CTPicture pictureXml = (CTPicture) imageToReplace.toReplace.getXmlObject();
	CTBlip pictureBlip = pictureXml.getBlipFill().getBlip();

	String relationId = pictureBlip.getEmbed();
	if(canRelationBeRemoved(containerDocument, relationId)) {
		// clean up the old picture data
		PptPoiBridge.removeRelation(containerDocument, containerDocument.getRelationById(relationId));
	}

	pictureBlip.setEmbed(rp.getRelationship().getId());

	imageToReplace.toReplace.setAnchor(newImageAnchor);
}
 
Example #2
Source File: ImageParserSupport.java    From tephra with MIT License 5 votes vote down vote up
void parse(XSLFSlide xslfSlide, XSLFPictureData xslfPictureData, JSONObject object) {
    if (!object.containsKey("alpha")) {
        parseImage(xslfSlide, xslfPictureData, object);

        return;
    }

    double alpha = object.getDoubleValue("alpha");
    if (alpha >= 1.0D) {
        parseImage(xslfSlide, xslfPictureData, object);

        return;
    }

    PackagePart packagePart = xslfPictureData.getPackagePart();
    POIXMLDocumentPart.RelationPart relationPart = xslfSlide.addRelation(null, XSLFRelation.IMAGES,
            new XSLFPictureData(packagePart));

    XSLFAutoShape xslfAutoShape = xslfSlide.createAutoShape();
    CTShape ctShape = (CTShape) xslfAutoShape.getXmlObject();
    CTBlipFillProperties ctBlipFillProperties = ctShape.getSpPr().addNewBlipFill();
    CTBlip ctBlip = ctBlipFillProperties.addNewBlip();
    ctBlip.setEmbed(relationPart.getRelationship().getId());
    ctBlip.setCstate(STBlipCompression.PRINT);
    ctBlip.addNewAlphaModFix().setAmt(numeric.toInt(alpha * 100000));
    ctBlipFillProperties.addNewSrcRect();
    ctBlipFillProperties.addNewStretch().addNewFillRect();
    xslfAutoShape.setAnchor(parserHelper.getRectangle(object));
    parserHelper.rotate(xslfAutoShape, object);
}
 
Example #3
Source File: ReplaceIndexPictureRefRenderPolicy.java    From poi-tl with Apache License 2.0 5 votes vote down vote up
@Override
public void doRender(XWPFPicture t, XWPFTemplate template) throws Exception {
    logger.info("Replace the picture data for the reference object: {}", t);
    NiceXWPFDocument doc = template.getXWPFDocument();
    try (InputStream ins = new ByteArrayInputStream(data)) {
        String relationId = doc.addPictureData(ins, fomart);
        CTPicture ctPic = t.getCTPicture();
        CTBlipFillProperties bill = ctPic.getBlipFill();
        CTBlip blip = bill.getBlip();
        blip.setEmbed(relationId);
    }
}
 
Example #4
Source File: ReplaceOptionalTextPictureRefRenderPolicy.java    From poi-tl with Apache License 2.0 4 votes vote down vote up
private void setPictureReference(XWPFPicture t, String relationId) {
    CTPicture ctPic = t.getCTPicture();
    CTBlipFillProperties bill = ctPic.getBlipFill();
    CTBlip blip = bill.getBlip();
    blip.setEmbed(relationId);
}