Java Code Examples for java.awt.Graphics.drawImage()

The following are Jave code examples for showing how to use drawImage() of the java.awt.Graphics class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: LinkGame   File: MenuPanel.java   View Source Code Vote up 7 votes
private void drawMenu(Graphics g) {
    g.drawImage(ImagesFactory.getImage(52), 0, 0, 750, 500, null);
    g.drawImage(start, firstX, firstY, item_width, item_height, null);
    g.drawImage(mode, firstX, firstY + space, item_width, item_height, null);
    g.drawImage(sort, firstX, firstY + space * 2, item_width, item_height, null);
    g.drawImage(set, firstX, firstY + space * 3, item_width, item_height, null);
    g.drawImage(about, firstX, firstY + space * 4, item_width, item_height, null);
}
 
Example 2
Project: Logisim   File: GridPainter.java   View Source Code Vote up 7 votes
public void paintGrid(Graphics g) {
	Rectangle clip = g.getClipBounds();
	Component dest = destination;
	double zoom = zoomFactor;
	int size = gridSize;

	if (!showGrid)
		return;

	Image img = gridImage;
	int w = gridImageWidth;
	if (img == null) {
		paintGridOld(g, size, zoom, clip);
		return;
	}
	int x0 = (clip.x / w) * w; // round down to multiple of w
	int y0 = (clip.y / w) * w;
	for (int x = 0; x < clip.width + w; x += w) {
		for (int y = 0; y < clip.height + w; y += w) {
			g.drawImage(img, x0 + x, y0 + y, dest);
		}
	}
}
 
Example 3
Project: OpenJSharp   File: ImagePrinter.java   View Source Code Vote up 6 votes
public int print(Graphics g, PageFormat pf, int index) {

        if (index > 0 || image == null) {
            return Printable.NO_SUCH_PAGE;
        }

        ((Graphics2D)g).translate(pf.getImageableX(), pf.getImageableY());
        int w = image.getWidth(null);
        int h = image.getHeight(null);
        int iw = (int)pf.getImageableWidth();
        int ih = (int)pf.getImageableHeight();

        // ensure image will fit
        int dw = w;
        int dh = h;
        if (dw > iw) {
            dh = (int)(dh * ( (float) iw / (float) dw)) ;
            dw = iw;
        }
        if (dh > ih) {
            dw = (int)(dw * ( (float) ih / (float) dh)) ;
            dh = ih;
        }
        // centre on page
        int dx = (iw - dw) / 2;
        int dy = (ih - dh) / 2;

        g.drawImage(image, dx, dy, dx+dw, dy+dh, 0, 0, w, h, null);
        return Printable.PAGE_EXISTS;
    }
 
Example 4
Project: VASSAL-src   File: ImageItem.java   View Source Code Vote up 6 votes
public void draw(Graphics g, GamePieceImage defn) {
  loadImage(defn);
  Point origin = layout.getPosition(this);

  if (isAntialias()) {
    ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                      RenderingHints.VALUE_ANTIALIAS_ON);
  }
  else {
    ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                      RenderingHints.VALUE_ANTIALIAS_OFF);
  }

  if (srcOp != null) {
    final BufferedImage img = srcOp.getImage();
    if (img != null) {
      g.drawImage(img, origin.x, origin.y, null);
    }
  }
}
 
Example 5
Project: JuggleMasterPro   File: ColorChooserDropDownJButton.java   View Source Code Vote up 6 votes
@Override final public void paintComponent(Graphics objPgraphics) {

		// Draw a colored rectangle in place of the button :
		final BufferedImage imgLbuffer =
											Constants.objS_GRAPHICS_CONFIGURATION.createCompatibleImage(ColorChooserDropDownJButton.intS_SIZE,
																										ColorChooserDropDownJButton.intS_SIZE,
																										Transparency.OPAQUE);
		final Graphics2D objLgraphics2D = (Graphics2D) imgLbuffer.getGraphics();
		final Color objLcolor = this.getGammaColor();
		objLgraphics2D.setColor(objLcolor);
		objLgraphics2D.fillRect(1, 1, ColorChooserDropDownJButton.intS_SIZE - 2, ColorChooserDropDownJButton.intS_SIZE - 2);
		if (this.isEnabled()) {
			final Image imgL =
								Tools.isLightColor(objLcolor) ? (this.objGjWindow.isVisible() ? this.imgGupB : this.imgGdownB)
																: (this.objGjWindow.isVisible() ? this.imgGupW : this.imgGdownW);
			if (imgL != null) {
				objLgraphics2D.drawImage(imgL, 0, 0, null);
			}
		}
		objLgraphics2D.setColor(this.isEnabled() ? Color.DARK_GRAY : Color.LIGHT_GRAY);
		objLgraphics2D.drawRect(0, 0, ColorChooserDropDownJButton.intS_SIZE, ColorChooserDropDownJButton.intS_SIZE);
		objLgraphics2D.dispose();
		objPgraphics.drawImage(imgLbuffer, 0, 0, null);
	}
 
Example 6
Project: jdk8u-jdk   File: AltTabCrashTest.java   View Source Code Vote up 5 votes
public void paint(Graphics g, Color c) {
    if (c != null) {
        g.setColor(c);
        g.fillRect(x, y, image.getWidth(null), image.getHeight(null));
    } else do {
        validateSprite();
        g.drawImage(image, x, y, null);
    } while (renderingIncomplete());
}
 
Example 7
Project: dynamic-dungeon   File: GuiPanel.java   View Source Code Vote up 5 votes
/**
    *
    * @param g
    */
   @Override
   public void paintComponent(final Graphics g) {
for (int x = 0; x < this.widthInTiles; x++) {
    for (int y = 0; y < this.heightInTiles; y++) {
	for (int z = 0; z < this.depthInTiles; z++) {
	    final BufferedImage img = this.state.tiles[x][y][z];
	    if (img != null) {
		g.drawImage(img, x * this.tileWidth, y * this.tileHeight, null);
	    }
	}
    }
}
   }
 
Example 8
Project: jdk8u-jdk   File: DrawBitmaskToSurfaceTest.java   View Source Code Vote up 5 votes
@Override
public void paint(final Graphics g) {
    try {
        System.err.println("paint frame....");
        g.drawImage(src, 30, 30, this);
    } catch (Throwable e) {
        theError = e;
    } finally {
        if (latch != null) {
            latch.countDown();
        }
    }
}
 
Example 9
Project: springboot-training   File: ImageUtil.java   View Source Code Vote up 5 votes
private byte[] resize(byte[] bytes, int newSize, int operation, String imgType) {
	if (bytes == null || WakaUtils.string.isEmpty(imgType) || newSize <= 0) {
		throw new ZhhrUtilException("获取文件大小失败!入参为空");
	}
	Image image = new ImageIcon(bytes).getImage();
	Image resizedImage = getResizedImage(image, newSize, operation);

	// This code ensures that all the pixels in the image are loaded.
	Image temp = new ImageIcon(resizedImage).getImage();

	// Create the buffered image.
	BufferedImage bufferedImage = new BufferedImage(temp.getWidth(null), temp.getHeight(null), BufferedImage.TYPE_INT_RGB);

	// Copy image to buffered image.
	Graphics g = bufferedImage.createGraphics();

	// Clear background and paint the image.
	// g.setColor(Color.white);
	g.fillRect(0, 0, temp.getWidth(null), temp.getHeight(null));
	g.drawImage(temp, 0, 0, null);
	g.dispose();

	// Soften.
	float softenFactor = 0.05f;
	float[] softenArray = { 0, softenFactor, 0, softenFactor, 1 - (softenFactor * 4), softenFactor, 0, softenFactor, 0 };
	Kernel kernel = new Kernel(3, 3, softenArray);
	ConvolveOp cOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
	bufferedImage = cOp.filter(bufferedImage, null);

	// 输出
	try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
		ImageIO.write(bufferedImage, imgType, os);
		return os.toByteArray();
	} catch (IOException e) {
		throw new ZhhrUtilException(e.getMessage(), e);
	}
}
 
Example 10
Project: JavaPlot   File: JPlot.java   View Source Code Vote up 5 votes
/**
 * Paint this component
 *
 * @param g Graphics handler for this component
 */
@Override
public void paint(Graphics g) {
    BufferedImage img = term.getImage();
    if (img == null)
        return;
    g.drawImage(img, 0, 0, null);
}
 
Example 11
Project: OpenJSharp   File: XYZApp.java   View Source Code Vote up 5 votes
@Override
public void paint(Graphics g) {
    if (md != null) {
        md.mat.unit();
        md.mat.translate(-(md.xmin + md.xmax) / 2,
                -(md.ymin + md.ymax) / 2,
                -(md.zmin + md.zmax) / 2);
        md.mat.mult(amat);
        // md.mat.scale(xfac, -xfac, 8 * xfac / getSize().width);
        md.mat.scale(xfac, -xfac, 16 * xfac / getSize().width);
        md.mat.translate(getSize().width / 2, getSize().height / 2, 8);
        md.transformed = false;
        if (backBuffer != null) {
            if (!backSize.equals(getSize())) {
                newBackBuffer();
            }
            backGC.setColor(getBackground());
            backGC.fillRect(0, 0, getSize().width, getSize().height);
            md.paint(backGC);
            g.drawImage(backBuffer, 0, 0, this);
        } else {
            md.paint(g);
        }
        setPainted();
    } else if (message != null) {
        g.drawString("Error in model:", 3, 20);
        g.drawString(message, 10, 40);
    }
}
 
Example 12
Project: DigitRecognizer   File: DigitManipulator.java   View Source Code Vote up 5 votes
public static BufferedImage moveToCenterAndScale(BufferedImage im, Consumer<BufferedImage> con, int pause)
{
    Graphics g;
    Point centerOfPixels = getCenterOfPixels(im);

    letDraw(im, con, pause);

    int width = im.getWidth();
    int heigth = im.getHeight();
    int dx = (width / 2) - centerOfPixels.x;
    int dy = (heigth / 2) - centerOfPixels.y;

    BufferedImage moved = new BufferedImage(width, heigth, BufferedImage.TYPE_INT_ARGB);
    g = moved.createGraphics();
    g.drawImage(im, dx, dy, null);

    letDraw(moved, con, pause);

    Rectangle movedBounds = getContentBounds(moved);
    int disX0 = width / 2 - movedBounds.x;
    int disY0 = heigth / 2 - movedBounds.y;
    int disX1 = (int)movedBounds.getMaxX() - width / 2;
    int disY1 = (int)movedBounds.getMaxY() - heigth / 2;
    int maxDis = Math.max(Math.max(disX0, disX1), Math.max(disY0, disY1));

    double scaleFactor = (width / 2.0 - OFFSET_TO_IMAGE_BORDER) / maxDis;

    int offset = (int)((-maxDis + width / 2) * scaleFactor) - OFFSET_TO_IMAGE_BORDER;

    BufferedImage scaled = new BufferedImage(width, heigth, BufferedImage.TYPE_INT_ARGB);
    g = scaled.createGraphics();
    g.drawImage(moved, -offset, -offset, (int)(width * scaleFactor), (int)(heigth * scaleFactor), null);

    letDraw(scaled, con, pause);

    return scaled;
}
 
Example 13
Project: Face-detection-and-recognition-desktop-application   File: FaceRecognizeFrame.java   View Source Code Vote up 5 votes
@Override
public void run() {
    synchronized (this) {
        while (runnable) {
            if (webSource.grab()) {
                try {
                    webSource.retrieve(fm);
                    Graphics g = cameraPane.getGraphics();
                    faceDetector.detectMultiScale(fm, faceDetections);

                    for (Rect rect : faceDetections.toArray()) {
                        Imgproc.rectangle(fm, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));
                        // rectCrop = new Rect(rect.x, rect.y, rect.width, rect.height);// crop only face

                    }
                    Highgui.imencode(".bmp", fm, mem);
                    Image im = ImageIO.read(new ByteArrayInputStream(mem.toArray()));
                    BufferedImage buff = (BufferedImage) im;
                    if (g.drawImage(buff, 0, 0, getWidth(), getHeight() - 150, 0, 0, buff.getWidth(), buff.getHeight(), null)) {
                        if (runnable == false) {
                            System.out.println("Paused ..... ");
                            this.wait();
                        }
                    }
                } catch (Exception ex) {
                    ex.toString();
                }

            }
        }
    }
}
 
Example 14
Project: Rummy   File: TitleScreenView.java   View Source Code Vote up 4 votes
@Override
public void render(Graphics g) {
	g.drawImage(Assets.BLACK_DECK, x, y, width, height, null);

}
 
Example 15
Project: openjdk-jdk10   File: SourceClippingBlitTest.java   View Source Code Vote up 4 votes
public void paint(Graphics g) {
    if (showErrors && done && grabbedBI != null) {
        g.drawImage(grabbedBI, 0, 0, null);
    }
}
 
Example 16
Project: Rummy   File: Deck.java   View Source Code Vote up 4 votes
@Override
public void render(Graphics g) {
	g.drawImage(Assets.BLACK_DECK, x, y, width, height, null);
}
 
Example 17
Project: AquamarineLake   File: MyFrame.java   View Source Code Vote up 4 votes
public void paint(Graphics g){
    g = contentPane.getGraphics();
    g.drawImage(videoCap.getOneFrame(), 0, 0, this);
}
 
Example 18
Project: SpotSpotter   File: CameraFacialRecognition.java   View Source Code Vote up 4 votes
@Override
public void paintComponent(Graphics g) {
	if (mImg != null) {
		g.drawImage(mImg, 0, 0, mImg.getWidth(), mImg.getHeight(), this);
	}
}
 
Example 19
Project: Star-Ride--RiverRaid   File: Top10.java   View Source Code Vote up 3 votes
/**
 * @Override
 * Sobrecarga el metodo paintComponent para poder dibujar la Imagen en el Panel
 */
@Override
public void paintComponent(Graphics g){
    
    g.drawImage(background, 0, 0, getWidth(), getHeight(),this);
    
}
 
Example 20
Project: MapAnalyst   File: Tile.java   View Source Code Vote up 2 votes
/**
 * Paints the tile-image on the {@link Graphics} <code>g</code> at the
 * position <code>x</code>/<code>y</code>.
 *
 * @param g the Graphics object
 * @param x x-coordinate in <code>g</code>
 * @param y y-coordinate in <code>g</code>
 */
public void paint(Graphics g, int x, int y) {
    if (image == null)
        return;
    g.drawImage(image, x, y, null);
}