void showFrameRate(Graphics g) { frames++; if (System.currentTimeMillis() > firstFrame + 1000) { firstFrame = System.currentTimeMillis(); fps = frames; frames = 0; } g.setColor(Color.white); g.fillRect(10, 12, 50, 15); g.setColor(Color.black); g.drawString((int) (fps + 0.5) + " fps", 10, 25); }
void drawZoomIndicator(Graphics g) { int x1 = 10; int y1 = 10; double aspectRatio = (double) imageHeight / imageWidth; int w1 = 64; if (aspectRatio > 1.0) w1 = (int) (w1 / aspectRatio); int h1 = (int) (w1 * aspectRatio); if (w1 < 4) w1 = 4; if (h1 < 4) h1 = 4; int w2 = (int) (w1 * ((double) srcRect.width / imageWidth)); int h2 = (int) (h1 * ((double) srcRect.height / imageHeight)); if (w2 < 1) w2 = 1; if (h2 < 1) h2 = 1; int x2 = (int) (w1 * ((double) srcRect.x / imageWidth)); int y2 = (int) (h1 * ((double) srcRect.y / imageHeight)); if (zoomIndicatorColor == null) zoomIndicatorColor = new Color(128, 128, 255); g.setColor(zoomIndicatorColor); ((Graphics2D) g).setStroke(Roi.onePixelWide); g.drawRect(x1, y1, w1, h1); if (w2 * h2 <= 200 || w2 < 10 || h2 < 10) g.fillRect(x1 + x2, y1 + y2, w2, h2); else g.drawRect(x1 + x2, y1 + y2, w2, h2); }