Java Code Examples for java.awt.image.BufferedImage#TRANSLUCENT
The following examples show how to use
java.awt.image.BufferedImage#TRANSLUCENT .
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: ImageScaler.java From TeaStore with Apache License 2.0 | 6 votes |
/** * Scales a given image by rendering the supplied image with the given width and * height into a new image and returning the new image. The method will throw an * {@link java.lang.IllegalArgumentException} if either of the two image sizes * is 0 or below. A {@link java.lang.NullPointerException} will be thrown if the * supplied image is null. * * @param image * Image to scale to the given width and height * @param width * Width to scale image to * @param height * Height to scale image to * @return New image scaled to the given width and height */ public static BufferedImage scale(BufferedImage image, int width, int height) { if (image == null) { log.error("The supplied image is null."); throw new NullPointerException("The supplied image is null."); } if (width <= 0) { log.error("The supplied pixel width is below 1."); throw new IllegalArgumentException("The supplied pixel width is below 1."); } if (height <= 0) { log.error("The supplied pixel height is below 1."); throw new IllegalArgumentException("The supplied pixel height is below 1."); } BufferedImage scaledImg = new BufferedImage(width, height, BufferedImage.TRANSLUCENT); Graphics2D graphics = scaledImg.createGraphics(); graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); graphics.drawImage(image, 0, 0, width, height, null); graphics.dispose(); return scaledImg; }
Example 2
Source File: ImageUtils.java From OpenRS with GNU General Public License v3.0 | 6 votes |
public static BufferedImage getScaledImage(BufferedImage src, double factor) { int finalw = src.getWidth(); int finalh = src.getHeight(); 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; }
Example 3
Source File: Utils.java From Genetic-Algorithm-Montage with Apache License 2.0 | 6 votes |
/** * Resizes an image using a Graphics2D object backed by a BufferedImage. * @param src - source image to scale * @param w - desired width * @param h - desired height * @return - the new resized image */ public static BufferedImage getScaledImage(BufferedImage src, int w, int h) { int finalw = w; int finalh = h; 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 g = resizedImg.createGraphics(); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.drawImage(src, 0, 0, finalw, finalh, null); g.dispose(); return resizedImg; }
Example 4
Source File: Mouse.java From haxademic with MIT License | 5 votes |
public static void setInvisibleCursor(Component comp) { Toolkit toolkit = Toolkit.getDefaultToolkit(); Point hotSpot = new Point(0,0); BufferedImage cursorImage = new BufferedImage(1, 1, BufferedImage.TRANSLUCENT); Cursor invisibleCursor = toolkit.createCustomCursor(cursorImage, hotSpot, "InvisibleCursor"); comp.setCursor(invisibleCursor); }
Example 5
Source File: ImageMerger.java From seventh with GNU General Public License v2.0 | 4 votes |
/** * @param args */ public static void main(String[] args) throws Exception { String imageDir = "C:\\UnityProjects\\UnitTest\\Assets\\screencaptures"; //"C:\\Users\\Tony\\Desktop\\SpriteSheetPacker\\Test\\allied_sprint"; File imageFiles = new File(imageDir); File[] files = imageFiles.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { //return pathname.getName().startsWith("legs"); return pathname.getName().endsWith(".png"); } }); Arrays.sort(files, new Comparator<File>() { @Override public int compare(File o1, File o2) { return (int) (o1.lastModified() - o2.lastModified()); } }); final int overwriteX = activeSettings.overwriteX; final int overwriteY = activeSettings.overwriteY; final int overwriteWidth = activeSettings.overwriteWidth; final int overwriteHeight = activeSettings.overwriteHeight; boolean scaleRow1 = activeSettings.scaleRow1; float scaleFactor = activeSettings.scaleFactor; int scaleX = (int)(overwriteWidth * scaleFactor); int scaleY = (int)(overwriteHeight * scaleFactor); int scaleWidth = overwriteWidth - (int)(overwriteWidth * scaleFactor); int scaleHeight = overwriteHeight - (int)(overwriteHeight * scaleFactor); int rows = activeSettings.rows; int cols = activeSettings.cols; BufferedImage[] images = new BufferedImage[rows * cols]; int j = 0; for(File f: files) { images[j] = ImageIO.read(f).getSubimage(overwriteX, overwriteY, overwriteWidth, overwriteHeight); j++; } int width = overwriteWidth * cols; width = nextPowerOf2(width); int height = overwriteHeight * rows; height = nextPowerOf2(height); BufferedImage spritesheet = new BufferedImage(width, height, BufferedImage.TRANSLUCENT); Graphics2D g = (Graphics2D) spritesheet.getGraphics(); int x = 0; int y = 0; for(int i = 0; i < images.length; i++) { if (x >= cols * overwriteWidth) { x = 0; y += overwriteHeight;////images[i].getHeight(); } if(i < cols && scaleRow1) { images[i] = ImageUtil.resizeImage(images[i], scaleWidth, scaleHeight); x += scaleX; y += scaleY; System.out.println(x + "," + y); g.drawImage(images[i], x, y, null); x -= scaleX; y -= scaleY; } else { System.out.println(x + "," + y); g.drawImage(images[i], x, y, null); } x += overwriteWidth;//images[i].getWidth(); } // spritesheet = ImageUtil.applyMask(spritesheet, new Color(0xA10082)); ImageIO.write(spritesheet, "png", new File(imageFiles, "/output.png")); }