/** Write out our image buffer as a PNG image. */ public void writeMosaicImage(File out) throws IOException { if (currPixels == Integer.MAX_VALUE) { throw new IOException("Unable to create arrange images in mosaic " + out); } if (currPixels > maxPixels) { throw new IOException( "Image too big (" + currPixels + " > " + maxPixels + ") -- see part 3.2 section G.5 " + "table G-4 \"Image size\".\n"); } BufferedImage buffer = new BufferedImage(currWidth, currHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = (Graphics2D) buffer.getGraphics(); graphics.setComposite(AlphaComposite.Src); graphics.setColor(Color.yellow); graphics.fillRect(0, 0, buffer.getWidth(), buffer.getHeight()); for (MosaicPart part : parts) { Rectangle r = part.getPlacement(); part.getImage().drawScaled(graphics, r, null); } boolean ok = ImageIO.write(buffer, "PNG", out); if (!ok) { throw new IOException("No writer found"); } }
void paintStatus(Graphics2D g) { if (parts == null) { return; } g.setComposite(AlphaComposite.Src); synchronized (parts) { if (currWidth == 0 || currHeight == 0 || progressComponent == null) { return; } float scaleX = ((float) progressComponent.getWidth()) / currWidth; float scaleY = ((float) progressComponent.getHeight()) / currHeight; if (scaleX < scaleY) { scaleY = scaleX; } else { scaleX = scaleY; } g.setColor(Color.yellow); g.fillRect(0, 0, (int) (currWidth * scaleX), (int) (currHeight * scaleY)); Rectangle p = new Rectangle(); for (MosaicPart part : parts) { Rectangle r = part.getPlacement(); p.x = (int) (r.x * scaleX); p.y = (int) (r.y * scaleY); p.width = (int) (r.width * scaleX); p.height = (int) (r.height * scaleY); part.getImage().drawScaled(g, p, progressComponent); } } }