Java Code Examples for java.awt.image.BufferedImage#copyData()
The following examples show how to use
java.awt.image.BufferedImage#copyData() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PixelatedImageSectionFilter.java From cognitivej with Apache License 2.0 | 6 votes |
@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; }
Example 2
Source File: TextureGallery.java From BlueMap with MIT License | 5 votes |
/** * 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; } }
Example 3
Source File: AbstractVideoCodec.java From jpexs-decompiler with GNU General Public License v3.0 | 5 votes |
/** 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); }
Example 4
Source File: ImageUtils.java From hifive-pitalium with Apache License 2.0 | 5 votes |
/** * 画像を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); }
Example 5
Source File: PoisonPlugin.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
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; }
Example 6
Source File: ImageTransform.java From scipio-erp with Apache License 2.0 | 5 votes |
/** * 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); }
Example 7
Source File: ImageUtils.java From ocr-neuralnet with GNU General Public License v3.0 | 5 votes |
/** * 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); }
Example 8
Source File: ImageComparisonUtil.java From image-comparison with Apache License 2.0 | 5 votes |
/** * 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); }
Example 9
Source File: GlobalUtil.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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); }
Example 10
Source File: PoisonPlugin.java From plugins with GNU General Public License v3.0 | 5 votes |
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; }
Example 11
Source File: ImageTools.java From GIFKR with GNU Lesser General Public License v3.0 | 4 votes |
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); }
Example 12
Source File: OccupancyMap.java From coordination_oru with GNU General Public License v3.0 | 4 votes |
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); }
Example 13
Source File: PaintShop.java From Carcassonne with Eclipse Public License 2.0 | 4 votes |
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); }
Example 14
Source File: ImageTools.java From pdfcompare with Apache License 2.0 | 4 votes |
public static BufferedImage deepCopy(BufferedImage image) { return new BufferedImage(image.getColorModel(), image.copyData(null), image.getColorModel().isAlphaPremultiplied(), null); }
Example 15
Source File: MultiImageFactory.java From cineast with MIT License | 4 votes |
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); }
Example 16
Source File: Sprite.java From yt-java-game with MIT License | 4 votes |
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); }
Example 17
Source File: Utils.java From Genetic-Algorithm-Montage with Apache License 2.0 | 4 votes |
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); }
Example 18
Source File: Sprite.java From ChatGameFontificator with The Unlicense | 4 votes |
private static BufferedImage copyImage(BufferedImage bi) { ColorModel cm = bi.getColorModel(); WritableRaster raster = bi.copyData(null); return new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null); }
Example 19
Source File: Utils.java From gpx-animator with Apache License 2.0 | 4 votes |
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); }