Dimension imgSize = getImageDimension(new ByteArrayInputStream(data.getData()), data.getPictureType()); Dimension anchorSize = ImageUtils.getDimensionFromAnchor(picture); final double scaledWidth = (scaleX == Double.MAX_VALUE) ? imgSize.getWidth() : anchorSize.getWidth()/EMU_PER_PIXEL * scaleX; int dy2 = 0; h = getRowHeightInPixels(sheet,row2++); if (isHSSF) { h *= 1 - anchor.getDy1()/256d; h += getRowHeightInPixels(sheet,row2++); double ch = getRowHeightInPixels(sheet,--row2); double delta = h - scaledHeight; if (isHSSF) {
BufferedImage img = r.read(0); int[] dpi = getResolution(r);
/** * Calculate the preferred size for this picture. * * @param scaleX the amount by which image width is multiplied relative to the original width. * @param scaleY the amount by which image height is multiplied relative to the original height. * @return HSSFClientAnchor with the preferred size for this image * @since POI 3.11 */ @Override public HSSFClientAnchor getPreferredSize(double scaleX, double scaleY){ ImageUtils.setPreferredSize(this, scaleX, scaleY); return getClientAnchor(); }
/** * Return the dimension of this image * * @param part the package part holding raw picture data * @param type type of the picture: {@link Workbook#PICTURE_TYPE_JPEG}, * {@link Workbook#PICTURE_TYPE_PNG} or {@link Workbook#PICTURE_TYPE_DIB} * * @return image dimension in pixels */ protected static Dimension getImageDimension(PackagePart part, int type){ try { return ImageUtils.getImageDimension(part.getInputStream(), type); } catch (IOException e){ //return a "singulariry" if ImageIO failed to read the image logger.log(POILogger.WARN, e); return new Dimension(); } }
int row2 = anchor.getRow1(); h = getRowHeightInPixels(sheet,row2++); if (isHSSF) { h *= 1 - anchor.getDy1()/256d; h += getRowHeightInPixels(sheet,row2++); h += getRowHeightInPixels(sheet,row2) * anchor.getDy2()/256; } else { h += anchor.getDy2()/(double)EMU_PER_PIXEL;
@Override public void inlineToXls(HSSFPatriarch patriarch, HSSFCell resultCell, Object paramValue, Matcher paramsMatcher) { try { Image image = new Image(paramValue, paramsMatcher); if (image.isValid()) { HSSFSheet sheet = resultCell.getSheet(); HSSFWorkbook workbook = sheet.getWorkbook(); int pictureIdx = workbook.addPicture(image.imageContent, Workbook.PICTURE_TYPE_JPEG); CreationHelper helper = workbook.getCreationHelper(); ClientAnchor anchor = helper.createClientAnchor(); anchor.setCol1(resultCell.getColumnIndex()); anchor.setRow1(resultCell.getRowIndex()); anchor.setCol2(resultCell.getColumnIndex()); anchor.setRow2(resultCell.getRowIndex()); if (patriarch == null) { throw new IllegalArgumentException(String.format("No HSSFPatriarch object provided. Charts on this sheet could cause this effect. Please check sheet %s", resultCell.getSheet().getSheetName())); } HSSFPicture picture = patriarch.createPicture(anchor, pictureIdx); Dimension size = ImageUtils.getDimensionFromAnchor(picture); double actualHeight = size.getHeight() / EMU_PER_PIXEL; double actualWidth = size.getWidth() / EMU_PER_PIXEL; picture.resize((double) image.width / actualWidth, (double) image.height / actualHeight); } } catch (IllegalArgumentException e) { throw new ReportFormattingException("An error occurred while inserting bitmap to xls file", e); } }
/** * Return the dimension of this image * * @param part the package part holding raw picture data * @param type type of the picture: {@link Workbook#PICTURE_TYPE_JPEG}, * {@link Workbook#PICTURE_TYPE_PNG} or {@link Workbook#PICTURE_TYPE_DIB} * * @return image dimension in pixels */ protected static Dimension getImageDimension(PackagePart part, int type){ try { return ImageUtils.getImageDimension(part.getInputStream(), type); } catch (IOException e){ //return a "singulariry" if ImageIO failed to read the image logger.log(POILogger.WARN, e); return new Dimension(); } }
private CTTransform2D createXfrm(XSSFClientAnchor anchor) { CTTransform2D xfrm = CTTransform2D.Factory.newInstance(); CTPoint2D off = xfrm.addNewOff(); off.setX(anchor.getDx1()); off.setY(anchor.getDy1()); XSSFSheet sheet = getSheet(); double widthPx = 0; for (int col = anchor.getCol1(); col < anchor.getCol2(); col++) { widthPx += sheet.getColumnWidthInPixels(col); } double heightPx = 0; for (int row = anchor.getRow1(); row < anchor.getRow2(); row++) { heightPx += ImageUtils.getRowHeightInPixels(sheet, row); } long width = Units.pixelToEMU((int) widthPx); long height = Units.pixelToEMU((int) heightPx); CTPositiveSize2D ext = xfrm.addNewExt(); ext.setCx(width - anchor.getDx1() + anchor.getDx2()); ext.setCy(height - anchor.getDy1() + anchor.getDy2()); // TODO: handle vflip/hflip return xfrm; }
@Override public void inlineToXls(HSSFPatriarch patriarch, HSSFCell resultCell, Object paramValue, Matcher paramsMatcher) { try { Image image = new Image(paramValue, paramsMatcher); if (image.isValid()) { HSSFSheet sheet = resultCell.getSheet(); HSSFWorkbook workbook = sheet.getWorkbook(); int pictureIdx = workbook.addPicture(image.imageContent, Workbook.PICTURE_TYPE_JPEG); CreationHelper helper = workbook.getCreationHelper(); ClientAnchor anchor = helper.createClientAnchor(); anchor.setCol1(resultCell.getColumnIndex()); anchor.setRow1(resultCell.getRowIndex()); anchor.setCol2(resultCell.getColumnIndex()); anchor.setRow2(resultCell.getRowIndex()); if (patriarch == null) { throw new IllegalArgumentException(String.format("No HSSFPatriarch object provided. Charts on this sheet could cause this effect. Please check sheet %s", resultCell.getSheet().getSheetName())); } HSSFPicture picture = patriarch.createPicture(anchor, pictureIdx); Dimension size = ImageUtils.getDimensionFromAnchor(picture); double actualHeight = size.getHeight() / EMU_PER_PIXEL; double actualWidth = size.getWidth() / EMU_PER_PIXEL; picture.resize((double) image.width / actualWidth, (double) image.height / actualHeight); } } catch (IllegalArgumentException e) { throw new ReportFormattingException("An error occurred while inserting bitmap to xls file", e); } }
Dimension imgSize = getImageDimension(new ByteArrayInputStream(data.getData()), data.getPictureType()); Dimension anchorSize = ImageUtils.getDimensionFromAnchor(picture); final double scaledWidth = (scaleX == Double.MAX_VALUE) ? imgSize.getWidth() : anchorSize.getWidth()/EMU_PER_PIXEL * scaleX; int dy2 = 0; h = getRowHeightInPixels(sheet,row2++); if (isHSSF) { h *= 1 - anchor.getDy1()/256d; h += getRowHeightInPixels(sheet,row2++); double ch = getRowHeightInPixels(sheet,--row2); double delta = h - scaledHeight; if (isHSSF) {
/** * Return the dimension of the embedded image in pixel * * @return image dimension in pixels */ @Override public Dimension getImageDimension(){ InternalWorkbook iwb = getPatriarch().getSheet().getWorkbook().getWorkbook(); EscherBSERecord bse = iwb.getBSERecord(getPictureIndex()); byte[] data = bse.getBlipRecord().getPicturedata(); int type = bse.getBlipTypeWin32(); return ImageUtils.getImageDimension(new ByteArrayInputStream(data), type); }
BufferedImage img = r.read(0); int[] dpi = getResolution(r);
/** * Calculate the preferred size for this picture. * * @param scaleX the amount by which image width is multiplied relative to the original width. * @param scaleY the amount by which image height is multiplied relative to the original height. * @return XSSFClientAnchor with the preferred size for this image */ public XSSFClientAnchor getPreferredSize(double scaleX, double scaleY){ Dimension dim = ImageUtils.setPreferredSize(this, scaleX, scaleY); CTPositiveSize2D size2d = ctPicture.getSpPr().getXfrm().getExt(); size2d.setCx((int)dim.getWidth()); size2d.setCy((int)dim.getHeight()); return getClientAnchor(); }
int row2 = anchor.getRow1(); h = getRowHeightInPixels(sheet,row2++); if (isHSSF) { h *= 1 - anchor.getDy1()/256d; h += getRowHeightInPixels(sheet,row2++); h += getRowHeightInPixels(sheet,row2) * anchor.getDy2()/256; } else { h += anchor.getDy2()/(double)EMU_PER_PIXEL;
/** * Return the dimension of this image * * @param part the package part holding raw picture data * @param type type of the picture: {@link Workbook#PICTURE_TYPE_JPEG}, * {@link Workbook#PICTURE_TYPE_PNG} or {@link Workbook#PICTURE_TYPE_DIB} * * @return image dimension in pixels */ protected static Dimension getImageDimension(PackagePart part, int type){ try { return ImageUtils.getImageDimension(part.getInputStream(), type); } catch (IOException e){ //return a "singulariry" if ImageIO failed to read the image logger.log(POILogger.WARN, e); return new Dimension(); } }
BufferedImage img = r.read(0); int[] dpi = getResolution(r);
/** * Calculate the preferred size for this picture. * * @param scaleX the amount by which image width is multiplied relative to the original width. * @param scaleY the amount by which image height is multiplied relative to the original height. * @return HSSFClientAnchor with the preferred size for this image * @since POI 3.11 */ @Override public HSSFClientAnchor getPreferredSize(double scaleX, double scaleY){ ImageUtils.setPreferredSize(this, scaleX, scaleY); return getClientAnchor(); }
private CTTransform2D createXfrm(XSSFClientAnchor anchor) { CTTransform2D xfrm = CTTransform2D.Factory.newInstance(); CTPoint2D off = xfrm.addNewOff(); off.setX(anchor.getDx1()); off.setY(anchor.getDy1()); XSSFSheet sheet = getSheet(); double widthPx = 0; for (int col = anchor.getCol1(); col < anchor.getCol2(); col++) { widthPx += sheet.getColumnWidthInPixels(col); } double heightPx = 0; for (int row = anchor.getRow1(); row < anchor.getRow2(); row++) { heightPx += ImageUtils.getRowHeightInPixels(sheet, row); } long width = Units.pixelToEMU((int) widthPx); long height = Units.pixelToEMU((int) heightPx); CTPositiveSize2D ext = xfrm.addNewExt(); ext.setCx(width - anchor.getDx1() + anchor.getDx2()); ext.setCy(height - anchor.getDy1() + anchor.getDy2()); // TODO: handle vflip/hflip return xfrm; }
/** * Return the dimension of this image * * @param part the package part holding raw picture data * @param type type of the picture: {@link Workbook#PICTURE_TYPE_JPEG}, * {@link Workbook#PICTURE_TYPE_PNG} or {@link Workbook#PICTURE_TYPE_DIB} * * @return image dimension in pixels */ protected static Dimension getImageDimension(PackagePart part, int type){ try { return ImageUtils.getImageDimension(part.getInputStream(), type); } catch (IOException e){ //return a "singulariry" if ImageIO failed to read the image logger.log(POILogger.WARN, e); return new Dimension(); } }
BufferedImage img = r.read(0); int[] dpi = getResolution(r);