use of org.apache.poi.xssf.usermodel.XSSFPictureData in project poi by apache.
the class SXSSFPicture method getPreferredSize.
/**
* Calculate the preferred size for this picture.
*
* @param scale the amount by which image dimensions are multiplied relative to the original size.
* @return XSSFClientAnchor with the preferred size for this image
*/
public XSSFClientAnchor getPreferredSize(double scale) {
XSSFClientAnchor anchor = getClientAnchor();
XSSFPictureData data = getPictureData();
Dimension size = getImageDimension(data.getPackagePart(), data.getPictureType());
double scaledWidth = size.getWidth() * scale;
double scaledHeight = size.getHeight() * scale;
float w = 0;
int col2 = anchor.getCol1() - 1;
while (w <= scaledWidth) {
w += getColumnWidthInPixels(++col2);
}
assert (w > scaledWidth);
double cw = getColumnWidthInPixels(col2);
double deltaW = w - scaledWidth;
int dx2 = (int) (XSSFShape.EMU_PER_PIXEL * (cw - deltaW));
anchor.setCol2(col2);
anchor.setDx2(dx2);
double h = 0;
int row2 = anchor.getRow1() - 1;
while (h <= scaledHeight) {
h += getRowHeightInPixels(++row2);
}
assert (h > scaledHeight);
double ch = getRowHeightInPixels(row2);
double deltaH = h - scaledHeight;
int dy2 = (int) (XSSFShape.EMU_PER_PIXEL * (ch - deltaH));
anchor.setRow2(row2);
anchor.setDy2(dy2);
CTPositiveSize2D size2d = getCTPicture().getSpPr().getXfrm().getExt();
size2d.setCx((long) (scaledWidth * XSSFShape.EMU_PER_PIXEL));
size2d.setCy((long) (scaledHeight * XSSFShape.EMU_PER_PIXEL));
return anchor;
}
use of org.apache.poi.xssf.usermodel.XSSFPictureData in project poi by apache.
the class TestLoadSaveXSSF method testLoadPictures.
// TODO filename string hard coded in XSSFWorkbook constructor in order to make ant test-ooxml target be successful.
public void testLoadPictures() throws Exception {
XSSFWorkbook workbook = new XSSFWorkbook(_ssSampels.openResourceAsStream("picture.xlsx"));
List<XSSFPictureData> pictures = workbook.getAllPictures();
assertEquals(1, pictures.size());
}
Aggregations