double ratio = (double) size.getHeightPx() / (double) size.getWidthPx(); log.debug("fit ratio: " + ratio); if (ratio > 1) {
public static CxCy scale(ImageInfo imageInfo, double xEmu, double yEmu) { ImageSize size = imageInfo.getSize(); double iwEmu = toEmu(size.getWidthPx(), size.getDpiHorizontal()); double ihEmu = toEmu(size.getHeightPx(), size.getDpiVertical()); return scaleToFit(iwEmu, ihEmu, xEmu, yEmu); }
double ratio = (double) size.getHeightPx() / (double) size.getWidthPx(); log.debug("fit ratio: " + ratio); if (ratio > 1) {
/** * Returns the size in pixels as a Dimension object. * @return the size in pixels */ public Dimension getDimensionPx() { return new Dimension(getWidthPx(), getHeightPx()); }
/** {@inheritDoc} */ public int getHeight() { return image.getSize().getHeightPx(); }
/** {@inheritDoc} */ public String toString() { StringBuffer sb = new StringBuffer(); sb.append("Size: "); sb.append(getWidthMpt()).append('x').append(getHeightMpt()).append(" mpt"); sb.append(" ("); sb.append(getWidthPx()).append('x').append(getHeightPx()).append(" px"); sb.append(" at ").append(getDpiHorizontal()).append('x').append(getDpiVertical()); sb.append(" dpi"); sb.append(")"); return sb.toString(); }
/** {@inheritDoc} */ public Rectangle2D getPrimitiveBounds() { return new Rectangle2D.Double(0, 0, image.getSize().getWidthPx(), image.getSize().getHeightPx()); }
/** {@inheritDoc} */ public Rectangle2D getPrimitiveBounds() { return new Rectangle2D.Double(0, 0, image.getSize().getWidthPx(), image.getSize().getHeightPx()); }
/** {@inheritDoc} */ public void primitivePaint(Graphics2D g2d) { int width = image.getSize().getWidthPx(); int height = image.getSize().getHeightPx(); Rectangle2D area = new Rectangle2D.Double(0, 0, width, height); Graphics2DImagePainter painter = image.getGraphics2DImagePainter(); painter.paint(g2d, area); }
private void updateIntrinsicSize(AFPImageObjectInfo imageObjectInfo, AFPPaintingState paintingState, ImageSize targetSize) { //Update image object info imageObjectInfo.setDataHeightRes((int)Math.round( targetSize.getDpiHorizontal() * 10)); imageObjectInfo.setDataWidthRes((int)Math.round( targetSize.getDpiVertical() * 10)); imageObjectInfo.setDataHeight(targetSize.getHeightPx()); imageObjectInfo.setDataWidth(targetSize.getWidthPx()); // set object area info int resolution = paintingState.getResolution(); AFPObjectAreaInfo objectAreaInfo = imageObjectInfo.getObjectAreaInfo(); objectAreaInfo.setResolution(resolution); }
public static CxCy scale(ImageInfo imageInfo, double xEmu, double yEmu) { ImageSize size = imageInfo.getSize(); double iwEmu = toEmu(size.getWidthPx(), size.getDpiHorizontal()); double ihEmu = toEmu(size.getHeightPx(), size.getDpiVertical()); return scaleToFit(iwEmu, ihEmu, xEmu, yEmu); }
@Override public void inlineToDocx(WordprocessingMLPackage wordPackage, Text text, Object paramValue, Matcher paramsMatcher) { try { Image image = new Image(paramValue, paramsMatcher); if (image.isValid()) { Part part = resolveTextPartForDOCX(text, wordPackage); BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordPackage, part, image.imageContent); int originalWidth = imagePart.getImageInfo().getSize().getWidthPx(); int originalHeight = imagePart.getImageInfo().getSize().getHeightPx(); double widthScale = (double) image.width / (double) originalWidth; double heightScale = (double) image.height / (double) originalHeight; double actualScale = Math.min(widthScale, heightScale); long targetWidth = Math.round(originalWidth * actualScale); long targetHeight = Math.round(originalHeight * actualScale); Inline inline = imagePart.createImageInline("", "", docxUniqueId1++, docxUniqueId2++, XlsxUtils.convertPxToEmu(targetWidth), XlsxUtils.convertPxToEmu(targetHeight), false); org.docx4j.wml.Drawing drawing = new org.docx4j.wml.ObjectFactory().createDrawing(); R run = (R) text.getParent(); run.getContent().add(drawing); drawing.getAnchorOrInline().add(inline); text.setValue(""); } } catch (Exception e) { throw new ReportFormattingException("An error occurred while inserting bitmap to docx file", e); } }
imageObjectInfo.setDataWidthRes((int)Math.round( effIntrinsicSize.getDpiVertical() * 10)); imageObjectInfo.setDataHeight(effIntrinsicSize.getHeightPx()); imageObjectInfo.setDataWidth(effIntrinsicSize.getWidthPx());
stripCount = 1; } else { stripCount = (int)Math.ceil(size.getHeightPx() / (double)fld.getAsLong(0));
/** {@inheritDoc} */ public void primitivePaint(Graphics2D g2d) { if (g2d instanceof NativeImageHandler) { NativeImageHandler nativeImageHandler = (NativeImageHandler) g2d; float x = 0; float y = 0; try { float width = image.getSize().getWidthPx(); float height = image.getSize().getHeightPx(); nativeImageHandler.addNativeImage(image, x, y, width, height); } catch (Exception e) { ctx.getUserAgent().displayError(e); } } else { // Not going directly into PDF so use // original implementation so filters etc work. if (origGraphicsNode == null) { // Haven't constructed base class Graphics Node, // so do so now. origGraphicsNode = superCreateGraphicsNode(ctx, imageElement, purl); } origGraphicsNode.primitivePaint(g2d); } }
if (size.getWidthPx() <= 0 || size.getHeightPx() <= 0) {
image.getSize().getHeightPx(), baos.toByteArray(), null); alphaMask.setPDFFilter(transFlate); alphaMask.disallowMultipleFilters();
private void updateDataObjectInfo(AFPDataObjectInfo dataObjectInfo, ImageRawStream rawStream, AFPResourceManager resourceManager) throws IOException { dataObjectInfo.setMimeType(rawStream.getFlavor().getMimeType()); AFPResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); if (!resourceInfo.levelChanged()) { resourceInfo.setLevel(resourceManager.getResourceLevelDefaults() .getDefaultResourceLevel(ResourceObject.TYPE_IMAGE)); } InputStream inputStream = rawStream.createInputStream(); try { dataObjectInfo.setData(IOUtils.toByteArray(inputStream)); } finally { IOUtils.closeQuietly(inputStream); } int dataHeight = rawStream.getSize().getHeightPx(); dataObjectInfo.setDataHeight(dataHeight); int dataWidth = rawStream.getSize().getWidthPx(); dataObjectInfo.setDataWidth(dataWidth); ImageSize imageSize = rawStream.getSize(); dataObjectInfo.setDataHeightRes((int) (imageSize.getDpiHorizontal() * 10)); dataObjectInfo.setDataWidthRes((int) (imageSize.getDpiVertical() * 10)); }
@Override public void inlineToDocx(WordprocessingMLPackage wordPackage, Text text, Object paramValue, Matcher paramsMatcher) { try { Image image = new Image(paramValue, paramsMatcher); if (image.isValid()) { BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordPackage, resolveTextPartForDOCX(text, wordPackage), image.imageContent); Inline inline = imagePart.createImageInline("", "", docxUniqueId1++, docxUniqueId2++, false); ImageSize oldSize = imagePart.getImageInfo().getSize(); double widthExtent = (double) image.width / oldSize.getWidthPx(); double heightExtent = (double) image.height / oldSize.getHeightPx(); inline.getExtent().setCx((long) (inline.getExtent().getCx() * widthExtent)); inline.getExtent().setCy((long) (inline.getExtent().getCy() * heightExtent)); org.docx4j.wml.Drawing drawing = new org.docx4j.wml.ObjectFactory().createDrawing(); R run = (R) text.getParent(); run.getContent().add(drawing); drawing.getAnchorOrInline().add(inline); text.setValue(""); } } catch (Exception e) { throw new ReportFormattingException("An error occurred while inserting bitmap to docx file", e); } }
stripCount = 1; } else { stripCount = (int)(info.getSize().getHeightPx() / fld.getAsLong(0));