java.awt.image.BufferedImage#copyData()源码实例Demo

下面列出了java.awt.image.BufferedImage#copyData() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: cognitivej   文件: PixelatedImageSectionFilter.java
@NotNull
@Override
public BufferedImage applyFilter(@NotNull BufferedImage bufferedImage) {
    Raster src = bufferedImage.getData();
    WritableRaster dest = src.createCompatibleWritableRaster();
    bufferedImage.copyData(dest);
    for (int y = pixelateSection.y; y < pixelateSection.y + pixelateSection.getHeight(); y += PIX_SIZE) {
        for (int x = pixelateSection.x; x < pixelateSection.x + pixelateSection.getWidth(); x += PIX_SIZE) {
            double[] pixel = new double[3];
            pixel = src.getPixel(x, y, pixel);
            for (int yd = y; (yd < y + PIX_SIZE) && (yd < dest.getHeight()); yd++) {
                for (int xd = x; (xd < x + PIX_SIZE) && (xd < dest.getWidth()); xd++) {
                    dest.setPixel(xd, yd, pixel);
                }
            }
        }
    }
    bufferedImage.setData(dest);
    return bufferedImage;
}
 
源代码2 项目: plugins   文件: PoisonPlugin.java
BufferedImage getSplat(int id, int damage)
{
	//Get a copy of the hitsplat to get a clean one each time
	final BufferedImage rawSplat = spriteManager.getSprite(id, 0);
	if (rawSplat == null)
	{
		return null;
	}

	final BufferedImage splat = new BufferedImage(
		rawSplat.getColorModel(),
		rawSplat.copyData(null),
		rawSplat.getColorModel().isAlphaPremultiplied(),
		null);

	final Graphics g = splat.getGraphics();
	g.setFont(FontManager.getRunescapeSmallFont());

	// Align the text in the centre of the hitsplat
	final FontMetrics metrics = g.getFontMetrics();
	final String text = String.valueOf(damage);
	final int x = (splat.getWidth() - metrics.stringWidth(text)) / 2;
	final int y = (splat.getHeight() - metrics.getHeight()) / 2 + metrics.getAscent();

	g.setColor(Color.BLACK);
	g.drawString(String.valueOf(damage), x + 1, y + 1);
	g.setColor(Color.WHITE);
	g.drawString(String.valueOf(damage), x, y);
	return splat;
}
 
源代码3 项目: BlueMap   文件: TextureGallery.java
/**
 * Loads a {@link Texture} from the {@link FileAccess} and the given path and returns it.<br>
 * If there is already a {@link Texture} with this path in this Gallery it replaces the {@link Texture} with the new one 
 * and the new one will have the same id as the old one.<br>
 * Otherwise the {@link Texture} will be added to the end of this gallery with the next available id.
 * @param fileAccess The {@link FileAccess} to load the image from.
 * @param path The path of the image on the {@link FileAccess}
 * @return The loaded {@link Texture}
 * @throws FileNotFoundException If there is no image in that FileAccess on that path
 * @throws IOException If an IOException occurred while loading the file
 */
public synchronized Texture loadTexture(FileAccess fileAccess, String path) throws FileNotFoundException, IOException {
	try (InputStream input = fileAccess.readFile(path)) {
		BufferedImage image = ImageIO.read(input);
		if (image == null) throw new IOException("Failed to read image: " + path);
		
		//crop off animation frames
		if (image.getHeight() > image.getWidth()){
			BufferedImage cropped = new BufferedImage(image.getWidth(), image.getWidth(), image.getType());
			image.copyData(cropped.getRaster());
			image = cropped;
		}
		
		//check halfTransparency
		boolean halfTransparent = checkHalfTransparent(image);
		
		//calculate color
		Vector4f color = calculateColor(image);
		
		//write to Base64
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		ImageIO.write(image, "png", os);
		String base64 = "data:image/png;base64," + Base64.getEncoder().encodeToString(os.toByteArray());
		
		//replace if texture with this path already exists
		Texture texture = textureMap.get(path);
		if (texture != null) {
			texture = new Texture(texture.getId(), path, color, halfTransparent, base64);
			textureMap.put(path, texture);
			textureList.set(texture.getId(), texture);
		} else {
			texture = new Texture(textureList.size(), path, color, halfTransparent, base64);
			textureMap.put(path, texture);
			textureList.add(texture);
		}
		
		return texture;
	}
}
 
源代码4 项目: MeteoInfo   文件: GlobalUtil.java
/**
 * Deep clone a BufferedIamge
 *
 * @param bi Original image
 * @return Cloned image
 */
public static BufferedImage deepCopy(BufferedImage bi) {
    ColorModel cm = bi.getColorModel();
    boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
    WritableRaster raster = bi.copyData(null);
    return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
}
 
源代码5 项目: image-comparison   文件: ImageComparisonUtil.java
/**
 * Make a copy of the {@link BufferedImage} object.
 *
 * @param image the provided image.
 * @return copy of the provided image.
 */
static BufferedImage deepCopy(BufferedImage image) {
    ColorModel cm = image.getColorModel();
    boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
    WritableRaster raster = image.copyData(image.getRaster().createCompatibleWritableRaster());
    return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
}
 
源代码6 项目: ocr-neuralnet   文件: ImageUtils.java
/**
 * Create a copy of the image.
 * @param image the image to copy.
 * @return the copy image.
 */
public static BufferedImage deepCopy(BufferedImage image) {
    return new BufferedImage(
            image.getColorModel(),
            image.copyData(null),
            image.isAlphaPremultiplied(),
            null);
}
 
源代码7 项目: scipio-erp   文件: ImageTransform.java
/**
 * SCIPIO: Attempts to create an exact copy of the original image in a new instance.
 * WARN: TODO: currently not guaranteed to work for all images.
 * Added 2017-07-14.
 * @return the cloned image
 */
public static BufferedImage cloneBufferedImage(BufferedImage image) {
    ColorModel colorModel = image.getColorModel();
    return new BufferedImage(colorModel,
            //image.copyData(image.getRaster().createCompatibleWritableRaster()),
            image.copyData(colorModel.createCompatibleWritableRaster(image.getWidth(null), image.getHeight(null))),
            colorModel.isAlphaPremultiplied(), null);
}
 
源代码8 项目: runelite   文件: PoisonPlugin.java
private BufferedImage getSplat(int id, int damage)
{
	//Get a copy of the hitsplat to get a clean one each time
	final BufferedImage rawSplat = spriteManager.getSprite(id, 0);
	if (rawSplat == null)
	{
		return null;
	}

	final BufferedImage splat = new BufferedImage(
		rawSplat.getColorModel(),
		rawSplat.copyData(null),
		rawSplat.getColorModel().isAlphaPremultiplied(),
		null);

	final Graphics g = splat.getGraphics();
	g.setFont(FontManager.getRunescapeSmallFont());

	// Align the text in the centre of the hitsplat
	final FontMetrics metrics = g.getFontMetrics();
	final String text = String.valueOf(damage);
	final int x = (splat.getWidth() - metrics.stringWidth(text)) / 2;
	final int y = (splat.getHeight() - metrics.getHeight()) / 2 + metrics.getAscent();

	g.setColor(Color.BLACK);
	g.drawString(String.valueOf(damage), x + 1, y + 1);
	g.setColor(Color.WHITE);
	g.drawString(String.valueOf(damage), x, y);
	return splat;
}
 
源代码9 项目: hifive-pitalium   文件: ImageUtils.java
/**
 * 画像をDeepCopyします。
 *
 * @param image DeepCopy元の{@link BufferedImage}
 * @return DeepCopyされた {@link BufferedImage}
 */
private static BufferedImage getDeepCopyImage(BufferedImage image) {
	ColorModel cm = image.getColorModel();
	boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
	WritableRaster raster = image.copyData(null);
	WritableRaster rasterChild = (WritableRaster) raster.createChild(0, 0, image.getWidth(), image.getHeight(),
			image.getMinX(), image.getMinY(), null);
	return new BufferedImage(cm, rasterChild, isAlphaPremultiplied, null);
}
 
源代码10 项目: jpexs-decompiler   文件: AbstractVideoCodec.java
/** Copies a buffered image. */
protected static BufferedImage copyImage(BufferedImage img) {
    ColorModel cm = img.getColorModel();
    boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
    WritableRaster raster = img.copyData(null);
    return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
}
 
源代码11 项目: yt-java-game   文件: Sprite.java
public Sprite getNewSubimage(int x, int y, int w, int h) {
	BufferedImage temp = image.getSubimage(x, y, w, h);
	BufferedImage newImage = new BufferedImage(image.getColorModel(), image.getRaster().createCompatibleWritableRaster(w,h), image.isAlphaPremultiplied(), null);
	temp.copyData(newImage.getRaster());
       return new Sprite(newImage);
}
 
源代码12 项目: GIFKR   文件: ImageTools.java
public static BufferedImage deepCopy(BufferedImage img) {
	ColorModel cm = img.getColorModel();
	boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
	WritableRaster raster = img.copyData(null);
	return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
}
 
源代码13 项目: coordination_oru   文件: OccupancyMap.java
private static BufferedImage deepCopy(BufferedImage bi) {
	 ColorModel cm = bi.getColorModel();
	 boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
	 WritableRaster raster = bi.copyData(null);
	 return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
}
 
源代码14 项目: Carcassonne   文件: PaintShop.java
private static BufferedImage deepCopy(BufferedImage image) {
    ColorModel model = image.getColorModel();
    boolean isAlphaPremultiplied = model.isAlphaPremultiplied();
    WritableRaster raster = image.copyData(null);
    return new BufferedImage(model, raster, isAlphaPremultiplied, null);
}
 
源代码15 项目: pdfcompare   文件: ImageTools.java
public static BufferedImage deepCopy(BufferedImage image) {
    return new BufferedImage(image.getColorModel(), image.copyData(null), image.getColorModel().isAlphaPremultiplied(), null);
}
 
源代码16 项目: cineast   文件: MultiImageFactory.java
public static BufferedImage copyBufferedImg(BufferedImage img) {
	ColorModel cm = img.getColorModel();
	boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
	WritableRaster raster = img.copyData(null);
	return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
}
 
源代码17 项目: Genetic-Algorithm-Montage   文件: Utils.java
public static BufferedImage deepCopy(BufferedImage bi) {
    ColorModel cm = bi.getColorModel();
    boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
    WritableRaster raster = bi.copyData(bi.getRaster().createCompatibleWritableRaster());
    return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
}
 
源代码18 项目: ChatGameFontificator   文件: Sprite.java
private static BufferedImage copyImage(BufferedImage bi)
{
    ColorModel cm = bi.getColorModel();
    WritableRaster raster = bi.copyData(null);
    return new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null);
}
 
源代码19 项目: gpx-animator   文件: Utils.java
public static BufferedImage deepCopy(final BufferedImage bi) {
    final ColorModel cm = bi.getColorModel();
    final boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
    final WritableRaster raster = bi.copyData(null);
    return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
}