本文整理汇总了Java中org.apache.poi.xslf.usermodel.XSLFPictureShape类的典型用法代码示例。如果您正苦于以下问题:Java XSLFPictureShape类的具体用法?Java XSLFPictureShape怎么用?Java XSLFPictureShape使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XSLFPictureShape类属于org.apache.poi.xslf.usermodel包,在下文中一共展示了XSLFPictureShape类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import org.apache.poi.xslf.usermodel.XSLFPictureShape; //导入依赖的package包/类
@Override
public boolean parse(XMLSlideShow xmlSlideShow, XSLFSlide xslfSlide, JSONObject object) {
String image = object.getString(getType());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Map<String, String> map = new HashMap<>();
http.get(image, null, null, map, outputStream);
if (map.isEmpty())
return false;
try {
String contenType = map.get("Content-Type");
XSLFPictureData xslfPictureData = xmlSlideShow.addPicture(parserHelper.getImage(object, contenType, outputStream),
getPictureType(image, contenType));
XSLFPictureShape xslfPictureShape = xslfSlide.createPicture(xslfPictureData);
xslfPictureShape.setAnchor(parserHelper.getRectangle(object));
parserHelper.rotate(xslfPictureShape, object);
return true;
} catch (IOException e) {
logger.warn(e, "解析图片[{}]时发生异常!", object.toJSONString());
return false;
}
}
示例2: parse
import org.apache.poi.xslf.usermodel.XSLFPictureShape; //导入依赖的package包/类
@Override
public boolean parse(XMLSlideShow xmlSlideShow, XSLFSlide xslfSlide, JSONObject object) {
try {
XSLFPictureData xslfPictureData = xmlSlideShow.addPicture(parserHelper.getImage(object, "image/png",
readSvg(object.getString("svg"))), PictureData.PictureType.PNG);
XSLFPictureShape xslfPictureShape = xslfSlide.createPicture(xslfPictureData);
xslfPictureShape.setAnchor(parserHelper.getRectangle(object));
parserHelper.rotate(xslfPictureShape, object);
return true;
} catch (IOException | TranscoderException e) {
logger.warn(e, "解析SVG图片[{}]时发生异常!", object.toJSONString());
return false;
}
}
示例3: processImageShape
import org.apache.poi.xslf.usermodel.XSLFPictureShape; //导入依赖的package包/类
private static boolean processImageShape(XSLFPictureShape imageShape, List<ImageToReplace> imagesToReplace, PptMapper mapper) {
Optional<PptVariable> imageVariable = parseHyperlinkVariable(imageShape);
if(shouldHide(imageVariable, mapper)) {
return true;
}
imageVariable
.flatMap(variable -> mapper.imageMapping(variable.getName()))
.ifPresent(imageMapper ->
imagesToReplace.add(ImageToReplace.of(imageShape, imageMapper))
);
styleShape(imageShape, imageVariable, mapper);
return false;
}
示例4: processShape
import org.apache.poi.xslf.usermodel.XSLFPictureShape; //导入依赖的package包/类
/**
* Handles shape modification
* @return true is the shape should be removed
*/
private static boolean processShape(XSLFShape shape, List<ImageToReplace> imagesToReplace, XMLSlideShow ppt, PptMapper mapper) {
if(shape instanceof XSLFTextShape) {
return processTextShape((XSLFTextShape) shape, mapper);
}
if(shape instanceof XSLFTable) {
return processTableShape((XSLFTable) shape, mapper);
}
if(shape instanceof XSLFPictureShape) {
return processImageShape((XSLFPictureShape) shape, imagesToReplace, mapper);
}
if(shape instanceof XSLFGroupShape) {
return processGroupShape((XSLFGroupShape) shape, ppt, mapper);
}
return false;
}
示例5: createImage
import org.apache.poi.xslf.usermodel.XSLFPictureShape; //导入依赖的package包/类
@Override
public XSLFPictureShape createImage(File imageFile, PictureType format) {
{
XMLSlideShow ppt = getPpt();
Dimension pgsize = ppt.getPageSize();
try {
// LOGGER.debug("{} {} ", pgsize.width, pgsize.height);
// BufferedImage img = new BufferedImage(pgsize.width,
// pgsize.height, BufferedImage.TYPE_4BYTE_ABGR);
// Graphics2D graphics = img.createGraphics();
// BufferedImage background = ImageIO.read(new
// File("C:\\Users\\KYJ\\Pictures\\10.png"));
// background.Graphics graphics = background.getGraphics();
// Rectangle2D.Float s = new Rectangle2D.Float(0, 0,
// pgsize.width, pgsize.height);
// graphics.fill(s);
// graphics.drawImage(background, 0, 0, Color.black, new
// ImageObserver() {
//
// @Override
// public boolean imageUpdate(Image img, int infoflags, int x,
// int y, int width, int height) {
// LOGGER.debug(img.toString());
// return true;
// }
// });
// graphics.setColor(Color.BLACK);
XSLFSlide slide = getSlide();
// XSLFAutoShape createAutoShape = slide.createAutoShape();
// createAutoShape.setFillColor(Color.BLACK);
// slide.addShape(shape);
slide.getBackground().setFillColor(Color.BLACK);
// slide.draw(graphics);
} catch (Exception e) {
e.printStackTrace();
}
}
{
XSLFTextShape placeholder = getSlide().getPlaceholder(0);
placeholder.setText(imageFile.getName());
}
{
XSLFTextShape bodyShape = getSlide().getPlaceholder(1);
// placeholder.clearText();
// placeholder.setText("Hello World\nMy Name is Kim.\nThis is PPT
// Wrtie Test.\n김영준\n0123456789");
List<XSLFShape> shapes = getSlide().getShapes();
XSLFShape xslfShape = shapes.get(1);
Rectangle2D anchor = xslfShape.getAnchor();
XSLFPictureShape shape = super.createImage(imageFile, getType(imageFile));
if (shape != null) {
shape.setAnchor(anchor);
}
getSlide().removeShape(bodyShape);
}
return null;
}
示例6: createImage
import org.apache.poi.xslf.usermodel.XSLFPictureShape; //导入依赖的package包/类
public XSLFPictureShape createImage(File imageFile) {
return createImage(imageFile, getType(imageFile));
}
示例7: replaceImage
import org.apache.poi.xslf.usermodel.XSLFPictureShape; //导入依赖的package包/类
private static void replaceImage(XMLSlideShow ppt, ShapeContainer<XSLFShape, ?> shapeContainer, ImageToReplace imageToReplace) {
byte[] newPictureResized = imageToReplace.imageMapper.getReplacementMode().resize(
imageToReplace.imageMapper.getValue(),
imageToReplace.imageMapper.getTargetFormat().name(),
(int) imageToReplace.toReplace.getAnchor().getWidth(),
(int) imageToReplace.toReplace.getAnchor().getHeight(),
imageToReplace.getImageMapper().getQualityFactory(),
imageToReplace.getImageMapper().getQualityMultiplicator()
);
if(newPictureResized == null) {
// if an error occurred during the resizement of the image, the replacement cannot be processed
return;
}
XSLFPictureData newPictureData = ppt.addPicture(newPictureResized, imageToReplace.imageMapper.getTargetFormat());
Rectangle2D newImageAnchor = computeNewImageAnchor(
imageToReplace.toReplace.getAnchor(),
newPictureResized,
imageToReplace.imageMapper.getReplacementMode(),
imageToReplace.imageMapper.getQualityMultiplicator()
);
if(shapeContainer instanceof POIXMLDocumentPart) {
replaceImageInPlace((POIXMLDocumentPart) shapeContainer, imageToReplace, newPictureData, newImageAnchor);
}
else if(shapeContainer instanceof XSLFGroupShape) {
replaceImageInPlace(((XSLFGroupShape) shapeContainer).getSheet(), imageToReplace, newPictureData, newImageAnchor);
}
// If the container is not a POIXMLDocumentPart or a XSLFGroupShape,
// the old image have to deleted along with its properties.
// The new image will just be place in the same area of the old image.
// This behavior is a fall back that should not append since
// I don't think the image container can be something else
// apart from POIXMLDocumentPart and XSLFGroupShape.
else {
XSLFPictureShape newPictureShape = (XSLFPictureShape) shapeContainer.createPicture(newPictureData);
newPictureShape.setAnchor(newImageAnchor);
shapeContainer.removeShape(imageToReplace.toReplace);
}
}