/** * Sets the image's resolution for interpreting the pixel size. * @param resolution the resolution in dpi */ public void setResolution(double resolution) { setResolution(resolution, resolution); }
/** * 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); }
size.setResolution(dpiHorz, dpiVert); size.calcSizeFromPixels();
size.setResolution(context.getSourceResolution()); size.calcPixelsFromSize(); info.setSize(size);
size.setSizeInMillipoints(widthMpt, heightMpt); size.setResolution(context.getSourceResolution()); size.calcPixelsFromSize(); info.setSize(size);
ImageSize size = new ImageSize(); size.setSizeInPixels(width, height); size.setResolution(dpi); size.calcSizeFromPixels(); info.setSize(size);
private void paintCornersAsBitmap(Graphics2DImagePainter painter, Rectangle boundingBox, String name) throws IFException { //TODO parameters ok? ImageInfo info = new ImageInfo(name, null); ImageSize size = new ImageSize(); size.setSizeInMillipoints(boundingBox.width, boundingBox.height); //Use the foreign attributes map to set image handling hints Map map = new java.util.HashMap(2); map.put(AFPForeignAttributeReader.RESOURCE_NAME, name); map.put(AFPForeignAttributeReader.RESOURCE_LEVEL, "print-file"); AFPRenderingContext context = (AFPRenderingContext) this.painter.createRenderingContext(/*map*/); size.setResolution(context.getPaintingState().getResolution()); size.calcPixelsFromSize(); info.setSize(size); ImageGraphics2D img = new ImageGraphics2D(info, painter); Map hints = new java.util.HashMap(); hints.put(ImageHandlerUtil.CONVERSION_MODE, ImageHandlerUtil.CONVERSION_MODE_BITMAP); hints.put("TARGET_RESOLUTION", context.getPaintingState().getResolution()); try { this.painter.drawImage(img, boundingBox, context, true, hints); } catch (IOException ioe) { throw new IFException( "I/O error while painting corner using a bitmap", ioe); } catch (ImageException ie) { throw new IFException( "Image error while painting corner using a bitmap", ie); } }
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; }
size.setResolution(context.getSourceResolution()); } else if (unit == 2) { size.setResolution(xRes, yRes); //Inch } else { size.setResolution( UnitConv.in2mm(xRes) / 10, UnitConv.in2mm(yRes) / 10); //Centimeters size.setResolution(context.getSourceResolution());
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(); } }
(int)Math.round(bbox.getWidth() * 1000), (int)Math.round(bbox.getHeight() * 1000)); size.setResolution(context.getSourceResolution()); size.calcPixelsFromSize(); info.setSize(size);
size.setResolution(context.getSourceResolution()); ImageIOUtil.extractResolution(iiometa, size); if (size.getWidthPx() <= 0 || size.getHeightPx() <= 0) {
private ImageSize determineSize(ImageInputStream in, ImageContext context) throws IOException, ImageException { in.mark(); ByteOrder oldByteOrder = in.getByteOrder(); try { ImageSize size = new ImageSize(); // BMP uses little endian notation! in.setByteOrder(ByteOrder.LITTLE_ENDIAN); //resolution in.skipBytes(WIDTH_OFFSET); int width = (int)in.readUnsignedInt(); int height = (int)in.readUnsignedInt(); in.skipBytes(HRES_PIXEL_OFFSET - WIDTH_OFFSET - 8); long hresPixel = in.readUnsignedInt(); long vresPixel = in.readUnsignedInt(); long hresMM = in.readUnsignedInt(); long vresMM = in.readUnsignedInt(); double resHorz = hresPixel / UnitConv.mm2in(hresMM); double resVert = vresPixel / UnitConv.mm2in(vresMM); size.setResolution(resHorz, resVert); width = (int)Math.round(UnitConv.mm2mpt(width / 100f)); height = (int)Math.round(UnitConv.mm2mpt(height / 100f)); size.setSizeInMillipoints(width, height); size.calcPixelsFromSize(); return size; } finally { in.setByteOrder(oldByteOrder); in.reset(); } }
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 (resolutionUnits == 3) { size.setResolution(resolution * UnitConv.IN2CM, resolution * UnitConv.IN2CM); } else if (resolutionUnits == 2) { size.setResolution(resolution, resolution); } else { size.setResolution(context.getSourceResolution()); size.setResolution(context.getSourceResolution()); size.calcSizeFromPixels();
size.setResolution(ua.getSourceResolution());
size.setResolution(xResDPI, yResDPI); size.calcSizeFromPixels(); return size;