当前位置: 首页>>代码示例>>Java>>正文


Java Graphics.drawImage方法代码示例

本文整理汇总了Java中java.awt.Graphics.drawImage方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics.drawImage方法的具体用法?Java Graphics.drawImage怎么用?Java Graphics.drawImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Graphics的用法示例。


在下文中一共展示了Graphics.drawImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: paintComponent

import java.awt.Graphics; //导入方法依赖的package包/类
@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);
	}
 
开发者ID:jugglemaster,项目名称:JuggleMasterPro,代码行数:25,代码来源:ColorChooserDropDownJButton.java

示例2: drawMenu

import java.awt.Graphics; //导入方法依赖的package包/类
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);
}
 
开发者ID:zhangjikai,项目名称:LinkGame,代码行数:9,代码来源:MenuPanel.java

示例3: paintGrid

import java.awt.Graphics; //导入方法依赖的package包/类
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);
		}
	}
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:24,代码来源:GridPainter.java

示例4: print

import java.awt.Graphics; //导入方法依赖的package包/类
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;
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:ImagePrinter.java

示例5: draw

import java.awt.Graphics; //导入方法依赖的package包/类
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);
    }
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:21,代码来源:ImageItem.java

示例6: paint

import java.awt.Graphics; //导入方法依赖的package包/类
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());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:AltTabCrashTest.java

示例7: paintComponent

import java.awt.Graphics; //导入方法依赖的package包/类
/**
    *
    * @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);
	    }
	}
    }
}
   }
 
开发者ID:wrldwzrd89,项目名称:dynamic-dungeon,代码行数:18,代码来源:GuiPanel.java

示例8: paint

import java.awt.Graphics; //导入方法依赖的package包/类
@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();
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:14,代码来源:DrawBitmaskToSurfaceTest.java

示例9: resize

import java.awt.Graphics; //导入方法依赖的package包/类
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);
	}
}
 
开发者ID:wooui,项目名称:springboot-training,代码行数:38,代码来源:ImageUtil.java

示例10: paint

import java.awt.Graphics; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:teras,项目名称:JavaPlot,代码行数:13,代码来源:JPlot.java

示例11: paint

import java.awt.Graphics; //导入方法依赖的package包/类
@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);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:XYZApp.java

示例12: moveToCenterAndScale

import java.awt.Graphics; //导入方法依赖的package包/类
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;
}
 
开发者ID:mirkoruether,项目名称:DigitRecognizer,代码行数:38,代码来源:DigitManipulator.java

示例13: run

import java.awt.Graphics; //导入方法依赖的package包/类
@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();
                }

            }
        }
    }
}
 
开发者ID:javaspecial,项目名称:Face-detection-and-recognition-desktop-application,代码行数:33,代码来源:FaceRecognizeFrame.java

示例14: render

import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void render(Graphics g) {
	g.drawImage(Assets.BLACK_DECK, x, y, width, height, null);

}
 
开发者ID:Ativelox,项目名称:Rummy,代码行数:6,代码来源:TitleScreenView.java

示例15: paint

import java.awt.Graphics; //导入方法依赖的package包/类
public void paint(Graphics g) {
    if (showErrors && done && grabbedBI != null) {
        g.drawImage(grabbedBI, 0, 0, null);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:SourceClippingBlitTest.java


注:本文中的java.awt.Graphics.drawImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。