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


Java Graphics2D.drawImage方法代码示例

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


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

示例1: draw

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * Draws the tile onto the specified context.
 *
 * @param gc
 *         The graphics context to draw with.
 *
 * @param imageCache
 *         The image cache to retrieve character images from.
 *
 * @param columnIndex
 *         The x-axis (column) coordinate where the character is to be drawn.
 *
 * @param rowIndex
 *         The y-axis (row) coordinate where the character is to be drawn.
 *
 * @throws NullPointerException
 *         If the gc or image cache are null.
 */
@Override
public void draw(final @NonNull Graphics2D gc, @NonNull final ImageCache imageCache, int columnIndex, int rowIndex) {
    if (super.updateCacheHash && super.isHidden() == false) {
        updateCacheHash();
        super.updateCacheHash = false;
    }

    final int fontWidth = imageCache.getFont().getWidth();
    final int fontHeight = imageCache.getFont().getHeight();

    columnIndex *= fontWidth;
    rowIndex *= fontHeight;

    super.getBoundingBox().setLocation(columnIndex, rowIndex);
    super.getBoundingBox().setSize(fontWidth, fontHeight);

    // Handle hidden state:
    if (super.isHidden()) {
        gc.setColor(super.getBackgroundColor());
        gc.fillRect(columnIndex, rowIndex, fontWidth, fontHeight);
    } else {
        final Image image = imageCache.retrieveFromCache(this);
        gc.drawImage(image, columnIndex, rowIndex, null);
    }
}
 
开发者ID:Valkryst,项目名称:VTerminal,代码行数:44,代码来源:AsciiTile.java

示例2: getScaledImage

import java.awt.Graphics2D; //导入方法依赖的package包/类
public static BufferedImage getScaledImage(BufferedImage src, double fraction){
	int finalw = (int)(src.getWidth()*fraction);
	int finalh = (int)(src.getHeight()*fraction);
	double factor = 1.0d;
	if(src.getWidth() > src.getHeight()){
		factor = ((double)src.getHeight()/(double)src.getWidth());
		finalh = (int)(finalw * factor);                
	}else{
		factor = ((double)src.getWidth()/(double)src.getHeight());
		finalw = (int)(finalh * factor);
	}   

	BufferedImage resizedImg = new BufferedImage(finalw, finalh, BufferedImage.TRANSLUCENT);
	Graphics2D g2 = resizedImg.createGraphics();
	g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
	g2.drawImage(src, 0, 0, finalw, finalh, null);
	g2.dispose();
	return resizedImg;
}
 
开发者ID:ForOhForError,项目名称:MTG-Card-Recognizer,代码行数:20,代码来源:ImageUtil.java

示例3: filter

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * Transforms source image using transform specified at the constructor.
 * The resulting transformed image is stored in the destination image if one
 * is provided; otherwise a new BufferedImage is created and returned. 
 *
 * @param src source image
 * @param dst destination image
 * @throws IllegalArgumentException if the source and destination image are
 *          the same
 * @return transformed source image.
 */
public final BufferedImage filter (BufferedImage src, BufferedImage dst)
{
  if (dst == src)
    throw new IllegalArgumentException("src image cannot be the same as "
                                     + "the dst image");

  // If the destination image is null, then use a compatible BufferedImage
  if (dst == null)
    dst = createCompatibleDestImage(src, null);

  Graphics2D gr = dst.createGraphics();
  gr.setRenderingHints(hints);
  gr.drawImage(src, transform, null);
  return dst;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:AffineTransformOp.java

示例4: run

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public BufferedImage run(final @NonNull BufferedImage image, final @NonNull AsciiCharacter character) {
    // Get the character image and filter it:
    BufferedImage charImage = swapColor(image, character.getBackgroundColor(), new Color(0, 0, 0, 0));
    charImage = new EdgeFilter().filter(charImage, null);

    // Combine image and background
    final BufferedImage result = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
    final Graphics2D gc = (Graphics2D) result.getGraphics();

    gc.setColor(character.getBackgroundColor());
    gc.fillRect(0, 0, result.getWidth(), result.getHeight());
    gc.drawImage(charImage, 1, 0, null);
    gc.drawImage(charImage, 0, 0, null);
    gc.dispose();

    return result;
}
 
开发者ID:Valkryst,项目名称:VTerminal,代码行数:19,代码来源:CharEdgeDetectionShader.java

示例5: call

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public byte[] call() throws Exception {
	BufferedImage original = ImageIO.read(_image_in);
	float ratio = (float)original.getHeight()/(float)original.getWidth();
	
	//if height > width take max_height else resize  
	int thumb_height = ratio>=1?MAX_HEIGHT:(int) (MAX_HEIGHT*ratio);
	//if width > height max_width else multiply by ratio
	int thumb_width = ratio<=1?MAX_WIDTH:(int) (MAX_WIDTH/ratio);
					
	BufferedImage result = new BufferedImage(thumb_width, thumb_height, original.getType());
	Graphics2D g = result.createGraphics();
	g.drawImage(original, 0, 0, thumb_width, thumb_height, null);
	g.dispose();
				
	ByteArrayOutputStream os = new ByteArrayOutputStream();
       ImageIO.write(result, _file_name.substring(_file_name.lastIndexOf(".")+1), os);
       
       return os.toByteArray();
}
 
开发者ID:awslabs,项目名称:aws-photosharing-example,代码行数:21,代码来源:ContentFacade.java

示例6: getScaledImage

import java.awt.Graphics2D; //导入方法依赖的package包/类
private BufferedImage getScaledImage() {
    BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = image.createGraphics();
    g2d.addRenderingHints(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
    g2d.drawImage(this.image.getImage(), 0, 0, getWidth(), getHeight(), null);
    return image;
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:8,代码来源:RNNfilter.java

示例7: test

import java.awt.Graphics2D; //导入方法依赖的package包/类
private static long test(Image bi, Image vi, AffineTransform atfm) {
    final Polygon p = new Polygon();
    p.addPoint(0, 0);
    p.addPoint(SIZE, 0);
    p.addPoint(0, SIZE);
    p.addPoint(SIZE, SIZE);
    p.addPoint(0, 0);
    Graphics2D g2d = (Graphics2D) vi.getGraphics();
    g2d.clip(p);
    g2d.transform(atfm);
    g2d.setComposite(AlphaComposite.SrcOver);
    final long start = System.nanoTime();
    g2d.drawImage(bi, 0, 0, null);
    final long time = System.nanoTime() - start;
    g2d.dispose();
    return time;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:UnmanagedDrawImagePerformance.java

示例8: DrawImagem

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void DrawImagem(Graphics2D g) {
    BufferedImage imgB = getImagem();
    if (imgB == null) {
        return;
    }
    Rectangle rec = getBounds();
    rec.grow(-2, -2);
    if (imgres == null) {
        imgres = imgB.getScaledInstance(rec.width, rec.height, Image.SCALE_SMOOTH);
    }

    Composite originalComposite = g.getComposite();
    if (alfa != 1f) {
        int type = AlphaComposite.SRC_OVER;
        g.setComposite(AlphaComposite.getInstance(type, alfa));
    }
    Image img = imgres;
    if (isDisablePainted()) {
        img = util.Utilidades.dye(new ImageIcon(imgres), disabledColor);
    }
    
    g.drawImage(img, rec.x, rec.y, null);
    g.setComposite(originalComposite);
}
 
开发者ID:chcandido,项目名称:brModelo,代码行数:25,代码来源:Desenhador.java

示例9: paint

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paint(Graphics g)
{
  Graphics2D g2d = (Graphics2D) g;
  g2d.drawImage(chessmap, 0, 0, null);
  for (int i = 0; i < 10; i++)
  {
    for (int j = 0; j < 9; j++)
    {
      if (chessBoard[i][j] == Eveluation.NOCHESS)
      {
        continue;
      }
      int x = j * GRILLEHEIGHT + BORDERHEIGHT;
      int y = i * GRILLEWIDTH + BORDERWIDTH;
      g2d.drawImage(chessmen[chessBoard[i][j] - 1], x, y, null);
    }
  }
}
 
开发者ID:beykery,项目名称:betacome,代码行数:20,代码来源:ChessPanel.java

示例10: draw

import java.awt.Graphics2D; //导入方法依赖的package包/类
private static void draw(Shape clip, Shape to, Image vi, BufferedImage bi,
                         int scale) {
    Graphics2D big = bi.createGraphics();
    big.setComposite(AlphaComposite.Src);
    big.setClip(clip);
    Rectangle toBounds = to.getBounds();
    int x1 = toBounds.x;

    int y1 = toBounds.y;
    int x2 = x1 + toBounds.width;
    int y2 = y1 + toBounds.height;
    big.drawImage(vi, x1, y1, x2, y2, 0, 0, toBounds.width / scale,
                  toBounds.height / scale, null);
    big.dispose();
    vi.flush();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:IncorrectClipSurface2SW.java

示例11: createMirroredImage

import java.awt.Graphics2D; //导入方法依赖的package包/类
public static BufferedImage createMirroredImage(Image image) {
    if(image == null)
        return null;
    final int width = image.getWidth(null);
    final int height = image.getHeight(null);
    BufferedImage result = new BufferedImage(width, height,
        BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = result.createGraphics();
    g.drawImage(image, width, 0, -width, height, null);
    g.dispose();
    return result;
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:13,代码来源:ImageLibrary.java

示例12: getImagePixels

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * Extracts image pixels into byte array "pixels"
 */
protected void getImagePixels() {
	if ((this.imgGbuffer.getWidth() != this.intGwidth) || (this.imgGbuffer.getHeight() != this.intGheight)
		|| (this.imgGbuffer.getType() != BufferedImage.TYPE_3BYTE_BGR)) {
		// create new image with right size/format
		final BufferedImage imgLbuffer = new BufferedImage(this.intGwidth, this.intGheight, BufferedImage.TYPE_3BYTE_BGR);
		final Graphics2D g = imgLbuffer.createGraphics();
		g.drawImage(this.imgGbuffer, 0, 0, null);
		this.imgGbuffer = imgLbuffer;
	}
	this.bytGpixelA = ((DataBufferByte) this.imgGbuffer.getRaster().getDataBuffer()).getData();
}
 
开发者ID:jugglemaster,项目名称:JuggleMasterPro,代码行数:15,代码来源:AnimatedGIFEncoder.java

示例13: renderImage

import java.awt.Graphics2D; //导入方法依赖的package包/类
public static void renderImage(final Graphics2D g, final Image image, final double x, final double y) {
  if (image == null) {
    return;
  }

  final AffineTransform t = AffineTransform.getTranslateInstance(x, y);
  g.drawImage(image, t, null);
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:9,代码来源:RenderEngine.java

示例14: drawFrame

import java.awt.Graphics2D; //导入方法依赖的package包/类
private final void drawFrame(final GifFrame fr) {
	int bgCol = 0; // Current background color value
	final int[] activeColTbl; // Active color table
	if (fr.hasLocColTbl) {
		activeColTbl = fr.localColTbl;
	} else {
		activeColTbl = globalColTbl;
		if (!fr.transpColFlag) { // Only use background color if there
			bgCol = globalColTbl[bgColIndex]; // is no transparency
		}
	}
	// Handle disposal, prepare current BufferedImage for drawing
	switch (prevDisposal) {
	case 2: // Next frame draws on background canvas
		final BufferedImage bgImage = prevImg;
		final int[] px = getPixels(bgImage);
		Arrays.fill(px, bgCol); // Set background color of bgImage
		prevImg = img; // Let previous point to current, dispose current
		img = bgImage; // Let current point to background image
		break;
	case 3: // Next frame draws on previous frame, so restore previous
		System.arraycopy(getPixels(prevImg), 0, getPixels(img), 0, wh);
		break;
	default: // Next frame draws on current frame, so backup current
		System.arraycopy(getPixels(img), 0, getPixels(prevImg), 0, wh);
		break;
	}
	// Get pixels from data stream
	int[] pixels = decode(fr, activeColTbl);
	if (fr.interlaceFlag) {
		pixels = deinterlace(pixels, fr); // Rearrange pixel lines
	}
	// Draw pixels on top of current image
	final int w = fr.width, h = fr.height, numPixels = w * h;
	final BufferedImage frame = new BufferedImage(w, h, 2); // 2 = ARGB
	System.arraycopy(pixels, 0, getPixels(frame), 0, numPixels);
	final Graphics2D g = img.createGraphics();
	g.drawImage(frame, fr.left, fr.top, null);
	g.dispose();
}
 
开发者ID:CalebKussmaul,项目名称:GIFKR,代码行数:41,代码来源:GifDecoder.java

示例15: paint

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void paint(Graphics g) {
	Graphics2D g2 = (Graphics2D) g;
	g2.scale(ZOOM, ZOOM);

	g2.drawImage(BACKGROUND, 0, 0, null);
	draw(g2, disp, 3, 1);

	if (score != null) {
		draw(g2, score, 15 - (score.getWidth() / 8), 3);
	}

	draw(g2, CARETS, 2, 7 + (selection.ordinal() * 2));
	boolean isSelected;

	isSelected = selection == Focus.MODE;
	draw(g2, isSelected ? MODE_HILITE : MODE_WORD, 2, 6);
	draw(g2, isSelected ? modeSel.wordHilite : modeSel.word, 4, 7);

	isSelected = selection == Focus.DIFFICULTY;
	draw(g2, isSelected ? DIFFICULTY_HILITE : DIFFICULTY_WORD, 2, 8);
	draw(g2, isSelected ? diffSel.wordHilite : diffSel.word, 4, 9);

	isSelected = selection == Focus.GAME;
	draw(g2, isSelected ? GAMES_HILITE : GAMES_WORD, 2, 10);
	draw(g2, isSelected ? GAME_NUMBERS_HILITE[games-1] : GAME_NUMBERS[games-1], 14, 11);

	isSelected = selection == Focus.START;
	draw(g2, isSelected ? START_HILITE : START_WORD, 7, 13);
}
 
开发者ID:fatmanspanda,项目名称:ALTTPMenuPractice,代码行数:30,代码来源:ControlScreen.java


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