/******************************************************************************* * * Executes an operation adding the elapsed time to the statistics. * * @param image the image to process * @param operation the operation to execute * @param operationName the name used for the statistics * @return the operation (as a convenience in case it carries * results) * *******************************************************************************/ protected <T extends Operation> T execute (EditableImage image, T operation, String operationName) { image.execute(operation); image.setNickName(operationName); registerTime(operationName, image); return operation; }
/******************************************************************************************************************* * * Creates a resized image. - FIXME should be removed * @deprecated * ******************************************************************************************************************/ public final EditableImage createResizedImage (final int width, final int height, final Quality quality) { double hScale = (double)width / (double)getWidth(); double vScale = (double)height / (double)getHeight(); ScaleOp scaleOp = new ScaleOp(hScale, vScale, quality); execute(scaleOp); return this; }
@Override public int print (final Graphics graphics, final PageFormat pageFormat, final int pageIndex) throws PrinterException { if (pageIndex > 0) { return Printable.NO_SUCH_PAGE; } Graphics2D g2d = (Graphics2D)graphics; g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); final double xScale = pageFormat.getImageableWidth() / image.getWidth(); final double yScale = pageFormat.getImageableHeight() / image.getHeight(); final double aspectScale = Math.min(xScale, yScale); final int width = (int)Math.round(image.getWidth() * aspectScale); final int height = (int)Math.round(image.getHeight() * aspectScale); image.execute(new PaintOp(g2d, 0, 0, width, height, null, null)); return Printable.PAGE_EXISTS; } };
@Test public void test1() throws IOException { Lookup.getDefault().lookup(ImplementationFactoryJ2D.class).registerImplementation(ChangeBufferTypeOp.class, ChangeBufferTypeJ2DOp.class); EditableImage image = EditableImage.create(new ReadOp(file_timezones32_png)); AssertJUnit.assertEquals(4, image.getBandCount()); image.execute(new ScaleOp(0.5, Quality.BEST)); AssertJUnit.assertEquals(4, image.getBandCount()); image.execute(new ChangeBufferTypeOp(BufferedImage.TYPE_3BYTE_BGR)); AssertJUnit.assertEquals(3, image.getBandCount()); File file = new File(tmp + "/result.jpg"); image.execute(new WriteOp("JPEG", file)); assertChecksum("ec0149544e522dbbb441b4f83a358425", file); } }