我使用下面的代码来合并word文档中的图像。对于宽度为377和高度为650的图像不起作用。这是我的代码片段。请告诉我如何解决这个问题,因为图像以字格式出现变焦比例为123%高度和123%宽度。
private void createImage(){
List<Object> objects = sourceDocumentEl.getBody().getEGBlockLevelElts();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, extension, baos);
baos.flush();
byte[] imageInByte = baos.toByteArray();
String filenameHint = null;
String altText = null;
int id1 = 0;
int id2 = 1;
org.docx4j.wml.P p = newImage(wordML, imageInByte,
filenameHint, altText, id1, id2);
objects .add(p);
}
public static org.docx4j.wml.P newImage( WordprocessingMLPackage wordMLPackage,
byte[] bytes,
String filenameHint, String altText,
int id1, int id2) throws Exception {
BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, bytes);
Inline inline = imagePart.createImageInline( filenameHint, altText,
id1, id2);
// Now add the inline in w:p/w:r/w:drawing
org.docx4j.wml.ObjectFactory factory = new org.docx4j.wml.ObjectFactory();
org.docx4j.wml.P p = factory.createP();
org.docx4j.wml.R run = factory.createR();
p.getParagraphContent().add(run);
org.docx4j.wml.Drawing drawing = factory.createDrawing();
run.getRunContent().add(drawing);
drawing.getAnchorOrInline().add(inline);
return p;
}
enter code here
答案 0 :(得分:0)
@jason -please检查附加图像,当我在上面的代码上运行时,你可以清楚地看到本地机器上的差异,以及当我尝试在VM机器或Ubuntu服务器上运行时,相同的代码。AfterImage < / p>
后图像变焦。