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); }
public static void displayImageInfo(ImageInfo info) { ImageSize size = info.getSize(); Dimension2D dPt = size.getDimensionPt(); Dimension dPx = size.getDimensionPx(); log.debug(info.getOriginalURI() + " " + info.getMimeType() + " " + Math.round(dPx.getWidth()) + "x" + Math.round(dPx.getHeight())); log.debug("Resolution:" + Math.round(size.getDpiHorizontal()) + "x" + Math.round(size.getDpiVertical())); log.debug("Print size: " + Math.round(dPt.getWidth() / 72) + "\" x" + Math.round(dPt.getHeight() / 72) + "\""); }
ImageSize size = new ImageSize(); icon.setForeground(fg); size.setSizeInMillipoints((int) (icon.getTrueIconWidth() * 1000), (int) (icon.getTrueIconHeight() * 1000)); size.setBaselinePositionFromBottom((int) (icon.getTrueIconDepth() * 1000)); size.setResolution(context.getSourceResolution()); size.calcPixelsFromSize(); info.setSize(size);
/** {@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(); }
ImageSize size = new ImageSize(); size.setSizeInPixels(width, height); size.setResolution(dpi); size.calcSizeFromPixels(); info.setSize(size); ImageWMF img = new ImageWMF(info, wmfStore);
final int imageIndex = 0; iiometa = reader.getImageMetadata(imageIndex); size = new ImageSize(); size.setSizeInPixels(reader.getWidth(imageIndex), reader.getHeight(imageIndex)); mime = reader.getOriginatingProvider().getMIMETypes()[0]; break; size.setResolution(context.getSourceResolution()); ImageIOUtil.extractResolution(iiometa, size); if (size.getWidthPx() <= 0 || size.getHeightPx() <= 0) { if (size.getWidthMpt() == 0) { size.calcSizeFromPixels();
this.intrinsicSize = imageInfo.getSize(); this.effIntrinsicSize = intrinsicSize; effIntrinsicSize.setSizeInPixels(renderedImage.getWidth(), renderedImage.getHeight()); && resampledDim.height < renderedImage.getHeight(); if (resample) { effIntrinsicSize = new ImageSize( resampledDim.width, resampledDim.height, resolution); effIntrinsicSize.getDpiHorizontal() * 10)); imageObjectInfo.setDataWidthRes((int)Math.round( effIntrinsicSize.getDpiVertical() * 10)); imageObjectInfo.setDataHeight(effIntrinsicSize.getHeightPx()); imageObjectInfo.setDataWidth(effIntrinsicSize.getWidthPx());
in.mark(); try { ImageSize size = new ImageSize(); JPEGFile jpeg = new JPEGFile(in); int xdensity = in.readUnsignedShort(); int ydensity = in.readUnsignedShort(); if (size.getDpiHorizontal() == 0) { if (densityUnits == 2) { size.setResolution( xdensity * UnitConv.IN2CM, ydensity * UnitConv.IN2CM); } else if (densityUnits == 1) { size.setResolution(xdensity, ydensity); } else { size.setResolution(context.getSourceResolution()); if (size.getWidthPx() != 0) { size.calcSizeFromPixels(); return size; size.setResolution(resolution * UnitConv.IN2CM, resolution * UnitConv.IN2CM); } else if (resolutionUnits == 2) { size.setResolution(resolution, resolution); } else {
public static void readPNGHeader(ImageInputStream inputStream, ImageSize size) throws IOException { SeekableStream seekStream = new ImageInputStreamSeekableStreamAdapter(inputStream) { public void close() throws IOException { } }; PNGImage pngImage = new PNGImage(seekStream); size.setSizeInPixels(pngImage.getWidth(), pngImage.getHeight()); double dpiHorz = size.getDpiHorizontal(); double dpiVert = size.getDpiVertical(); if (pngImage.unitSpecifier == 1) { if (pngImage.xPixelsPerUnit != 0) { dpiHorz = pngImage.xPixelsPerUnit * 0.0254; } if (pngImage.yPixelsPerUnit != 0) { dpiVert = pngImage.yPixelsPerUnit * 0.0254; } } size.setResolution(dpiHorz, dpiVert); size.calcSizeFromPixels(); } }
/** {@inheritDoc} */ public int getWidth() { return image.getSize().getWidthPx(); }
at.translate(pos.x, pos.y); double sx = pos.getWidth() / (double)info.getSize().getWidthMpt(); double sy = pos.getHeight() / (double)info.getSize().getHeightMpt(); sx *= sourceResolution / info.getSize().getDpiHorizontal(); sy *= sourceResolution / info.getSize().getDpiVertical(); at.scale(sx, sy); RenderedImage rend = imageRend.getRenderedImage();
ImageSize ditherBitmapSize = new ImageSize( ditherSize.width, ditherSize.height, resolution); imageObjectInfo.setDataHeightRes((int)Math.round( ditherBitmapSize.getDpiHorizontal() * 10)); imageObjectInfo.setDataWidthRes((int)Math.round( ditherBitmapSize.getDpiVertical() * 10)); imageObjectInfo.setDataWidth(ditherSize.width); imageObjectInfo.setDataHeight(ditherSize.height);
/** {@inheritDoc} */ public int getHeight() { return image.getSize().getHeightPx(); }
private ImageSize determineSize(byte[] header, ImageContext context, ImageInputStream in) throws IOException { int [] dim = extractImageMetadata(in); ImageSize size = new ImageSize(dim[0], dim[1], context.getSourceResolution()); size.calcSizeFromPixels(); return size; }
/** * Constructor. * @param widthPx the width of the image in pixels * @param heightPx the height of the image in pixels * @param dpiHorizontal the horizontal resolution in dots per inch * @param dpiVertical the vertical resolution in dots per inch */ public ImageSize(int widthPx, int heightPx, double dpiHorizontal, double dpiVertical) { setSizeInPixels(widthPx, heightPx); setResolution(dpiHorizontal, dpiVertical); }
public ImageInfo preloadImage(String uri, Source src, ImageContext context) throws ImageException, IOException { if (!ImageUtil.hasImageInputStream(src)) { return null; } ImageInputStream in = ImageUtil.needImageInputStream(src); long bb = ByteBuffer.wrap(getHeader(in, 8)).getLong(); if (bb != PNGConstants.PNG_SIGNATURE) { return null; } in.mark(); ImageSize size = new ImageSize(); //Resolution (first a default, then try to read the metadata) size.setResolution(context.getSourceResolution()); try { PNGImageDecoder.readPNGHeader(in, size); } finally { in.reset(); } ImageInfo info = new ImageInfo(uri, "image/png"); info.setSize(size); return info; }
private void paintMarksAsBitmap(Graphics2DImagePainter painter, Rectangle boundingBox) throws IFException { ImageInfo info = new ImageInfo(null, null); ImageSize size = new ImageSize(); size.setSizeInMillipoints(boundingBox.width, boundingBox.height); info.setSize(size); ImageGraphics2D img = new ImageGraphics2D(info, painter); Map hints = new java.util.HashMap(); if (isSpeedOptimized()) { //Gray text may not be painted in this case! We don't get dithering in Sun JREs. //But this approach is about twice as fast as the grayscale image. hints.put(ImageProcessingHints.BITMAP_TYPE_INTENT, ImageProcessingHints.BITMAP_TYPE_INTENT_MONO); } else { hints.put(ImageProcessingHints.BITMAP_TYPE_INTENT, ImageProcessingHints.BITMAP_TYPE_INTENT_GRAY); } hints.put(ImageHandlerUtil.CONVERSION_MODE, ImageHandlerUtil.CONVERSION_MODE_BITMAP); PCLRenderingContext context = (PCLRenderingContext)createRenderingContext(); context.setSourceTransparencyEnabled(true); try { drawImage(img, boundingBox, context, true, hints); } catch (IOException ioe) { throw new IFException( "I/O error while painting marks using a bitmap", ioe); } catch (ImageException ie) { throw new IFException( "Error while painting marks using a bitmap", ie); } }
/** * Sets the image's resolution for interpreting the pixel size. * @param resolution the resolution in dpi */ public void setResolution(double resolution) { setResolution(resolution, resolution); }
private PDFXObject addRenderedImage(String key, RenderedImage img) { ImageInfo info = new ImageInfo(null, "image/unknown"); ImageSize size = new ImageSize(img.getWidth(), img.getHeight(), GraphicsConstants.DEFAULT_DPI); info.setSize(size); ImageRendered imgRend = new ImageRendered(info, img, null); ImageRenderedAdapter adapter = new ImageRenderedAdapter(imgRend, key); PDFXObject xObject = pdfDoc.addImage(resourceContext, adapter); flushPDFDocument(); return xObject; }