示例#1
0
 void drawRoiLabel(Graphics g, int index, Roi roi) {
   Rectangle r = roi.getBounds();
   int x = screenX(r.x);
   int y = screenY(r.y);
   double mag = getMagnification();
   int width = (int) (r.width * mag);
   int height = (int) (r.height * mag);
   int size = width > 40 && height > 40 ? 12 : 9;
   if (font != null) {
     g.setFont(font);
     size = font.getSize();
   } else if (size == 12) g.setFont(largeFont);
   else g.setFont(smallFont);
   boolean drawingList = index >= LIST_OFFSET;
   if (drawingList) index -= LIST_OFFSET;
   String label = "" + (index + 1);
   if (drawNames && roi.getName() != null) label = roi.getName();
   FontMetrics metrics = g.getFontMetrics();
   int w = metrics.stringWidth(label);
   x = x + width / 2 - w / 2;
   y = y + height / 2 + Math.max(size / 2, 6);
   int h = metrics.getAscent() + metrics.getDescent();
   if (bgColor != null) {
     g.setColor(bgColor);
     g.fillRoundRect(x - 1, y - h + 2, w + 1, h - 3, 5, 5);
   }
   if (!drawingList && labelRects != null && index < labelRects.length)
     labelRects[index] = new Rectangle(x - 1, y - h + 2, w + 1, h);
   g.setColor(labelColor);
   g.drawString(label, x, y - 2);
   g.setColor(defaultColor);
 }
示例#2
0
 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);
 }
示例#3
0
 void drawRoi(Graphics g, Roi roi, int index) {
   int type = roi.getType();
   ImagePlus imp2 = roi.getImage();
   roi.setImage(imp);
   Color saveColor = roi.getStrokeColor();
   if (saveColor == null) roi.setStrokeColor(defaultColor);
   if (roi instanceof TextRoi) ((TextRoi) roi).drawText(g);
   else roi.drawOverlay(g);
   roi.setStrokeColor(saveColor);
   if (index >= 0) {
     if (roi == currentRoi) g.setColor(Roi.getColor());
     else g.setColor(defaultColor);
     drawRoiLabel(g, index, roi);
   }
   if (imp2 != null) roi.setImage(imp2);
   else roi.setImage(null);
 }
示例#4
0
 // Use double buffer to reduce flicker when drawing complex ROIs.
 // Author: Erik Meijering
 void paintDoubleBuffered(Graphics g) {
   final int srcRectWidthMag = (int) (srcRect.width * magnification);
   final int srcRectHeightMag = (int) (srcRect.height * magnification);
   if (offScreenImage == null
       || offScreenWidth != srcRectWidthMag
       || offScreenHeight != srcRectHeightMag) {
     offScreenImage = createImage(srcRectWidthMag, srcRectHeightMag);
     offScreenWidth = srcRectWidthMag;
     offScreenHeight = srcRectHeightMag;
   }
   Roi roi = imp.getRoi();
   try {
     if (imageUpdated) {
       imageUpdated = false;
       imp.updateImage();
     }
     Graphics offScreenGraphics = offScreenImage.getGraphics();
     Java2.setBilinearInterpolation(offScreenGraphics, Prefs.interpolateScaledImages);
     Image img = imp.getImage();
     if (img != null)
       offScreenGraphics.drawImage(
           img,
           0,
           0,
           srcRectWidthMag,
           srcRectHeightMag,
           srcRect.x,
           srcRect.y,
           srcRect.x + srcRect.width,
           srcRect.y + srcRect.height,
           null);
     if (overlay != null) drawOverlay(offScreenGraphics);
     if (showAllROIs) drawAllROIs(offScreenGraphics);
     if (roi != null) drawRoi(roi, offScreenGraphics);
     if (srcRect.width < imageWidth || srcRect.height < imageHeight)
       drawZoomIndicator(offScreenGraphics);
     if (IJ.debugMode) showFrameRate(offScreenGraphics);
     g.drawImage(offScreenImage, 0, 0, null);
   } catch (OutOfMemoryError e) {
     IJ.outOfMemory("Paint");
   }
 }
示例#5
0
 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);
 }
示例#6
0
 void initGraphics(Graphics g, Color textColor, Color defaultColor) {
   if (smallFont == null) {
     smallFont = new Font("SansSerif", Font.PLAIN, 9);
     largeFont = new Font("SansSerif", Font.PLAIN, 12);
   }
   if (textColor != null) {
     labelColor = textColor;
     if (overlay != null && overlay.getDrawBackgrounds())
       bgColor =
           new Color(
               255 - labelColor.getRed(), 255 - labelColor.getGreen(), 255 - labelColor.getBlue());
     else bgColor = null;
   } else {
     int red = defaultColor.getRed();
     int green = defaultColor.getGreen();
     int blue = defaultColor.getBlue();
     if ((red + green + blue) / 3 < 128) labelColor = Color.white;
     else labelColor = Color.black;
     bgColor = defaultColor;
   }
   this.defaultColor = defaultColor;
   g.setColor(defaultColor);
 }
示例#7
0
 public void paint(Graphics g) {
   Roi roi = imp.getRoi();
   if (roi != null || showAllROIs || overlay != null) {
     if (roi != null) roi.updatePaste();
     if (!IJ.isMacOSX() && imageWidth != 0) {
       paintDoubleBuffered(g);
       return;
     }
   }
   try {
     if (imageUpdated) {
       imageUpdated = false;
       imp.updateImage();
     }
     Java2.setBilinearInterpolation(g, Prefs.interpolateScaledImages);
     Image img = imp.getImage();
     if (img != null)
       g.drawImage(
           img,
           0,
           0,
           (int) (srcRect.width * magnification),
           (int) (srcRect.height * magnification),
           srcRect.x,
           srcRect.y,
           srcRect.x + srcRect.width,
           srcRect.y + srcRect.height,
           null);
     if (overlay != null) drawOverlay(g);
     if (showAllROIs) drawAllROIs(g);
     if (roi != null) drawRoi(roi, g);
     if (srcRect.width < imageWidth || srcRect.height < imageHeight) drawZoomIndicator(g);
     if (IJ.debugMode) showFrameRate(g);
   } catch (OutOfMemoryError e) {
     IJ.outOfMemory("Paint");
   }
 }