List of usage examples for java.awt.image BufferedImage getHeight
public int getHeight()
From source file:de.mprengemann.intellij.plugin.androidicons.images.ImageUtils.java
private static void enforceBorderColors(BufferedImage inputImage) { Graphics2D g = inputImage.createGraphics(); g.setBackground(new Color(0, 0, 0, 0)); g.clearRect(1, 1, inputImage.getWidth() - 2, inputImage.getHeight() - 2); g.dispose();// w w w . java 2s . c om int w = inputImage.getWidth(); int h = inputImage.getHeight(); int[] rgb = new int[w * h]; inputImage.getRGB(0, 0, w, h, rgb, 0, w); for (int i = 0; i < rgb.length; i++) { if ((0xff000000 & rgb[i]) != 0) { rgb[i] = 0xff000000; } } inputImage.setRGB(0, 0, w, h, rgb, 0, w); }
From source file:Snippet156.java
static ImageData convertToSWT(BufferedImage bufferedImage) { if (bufferedImage.getColorModel() instanceof DirectColorModel) { DirectColorModel colorModel = (DirectColorModel) bufferedImage.getColorModel(); PaletteData palette = new PaletteData(colorModel.getRedMask(), colorModel.getGreenMask(), colorModel.getBlueMask()); ImageData data = new ImageData(bufferedImage.getWidth(), bufferedImage.getHeight(), colorModel.getPixelSize(), palette); WritableRaster raster = bufferedImage.getRaster(); int[] pixelArray = new int[3]; for (int y = 0; y < data.height; y++) { for (int x = 0; x < data.width; x++) { raster.getPixel(x, y, pixelArray); int pixel = palette.getPixel(new RGB(pixelArray[0], pixelArray[1], pixelArray[2])); data.setPixel(x, y, pixel); }/*from www. ja va 2 s .c om*/ } return data; } else if (bufferedImage.getColorModel() instanceof IndexColorModel) { IndexColorModel colorModel = (IndexColorModel) bufferedImage.getColorModel(); int size = colorModel.getMapSize(); byte[] reds = new byte[size]; byte[] greens = new byte[size]; byte[] blues = new byte[size]; colorModel.getReds(reds); colorModel.getGreens(greens); colorModel.getBlues(blues); RGB[] rgbs = new RGB[size]; for (int i = 0; i < rgbs.length; i++) { rgbs[i] = new RGB(reds[i] & 0xFF, greens[i] & 0xFF, blues[i] & 0xFF); } PaletteData palette = new PaletteData(rgbs); ImageData data = new ImageData(bufferedImage.getWidth(), bufferedImage.getHeight(), colorModel.getPixelSize(), palette); data.transparentPixel = colorModel.getTransparentPixel(); WritableRaster raster = bufferedImage.getRaster(); int[] pixelArray = new int[1]; for (int y = 0; y < data.height; y++) { for (int x = 0; x < data.width; x++) { raster.getPixel(x, y, pixelArray); data.setPixel(x, y, pixelArray[0]); } } return data; } return null; }
From source file:org.eclipse.swt.snippets.Snippet156.java
static ImageData convertToSWT(BufferedImage bufferedImage) { if (bufferedImage.getColorModel() instanceof DirectColorModel) { DirectColorModel colorModel = (DirectColorModel) bufferedImage.getColorModel(); PaletteData palette = new PaletteData(colorModel.getRedMask(), colorModel.getGreenMask(), colorModel.getBlueMask()); ImageData data = new ImageData(bufferedImage.getWidth(), bufferedImage.getHeight(), colorModel.getPixelSize(), palette); for (int y = 0; y < data.height; y++) { for (int x = 0; x < data.width; x++) { int rgb = bufferedImage.getRGB(x, y); int pixel = palette.getPixel(new RGB((rgb >> 16) & 0xFF, (rgb >> 8) & 0xFF, rgb & 0xFF)); data.setPixel(x, y, pixel); if (colorModel.hasAlpha()) { data.setAlpha(x, y, (rgb >> 24) & 0xFF); }/*from w ww . j a v a 2 s .co m*/ } } return data; } else if (bufferedImage.getColorModel() instanceof IndexColorModel) { IndexColorModel colorModel = (IndexColorModel) bufferedImage.getColorModel(); int size = colorModel.getMapSize(); byte[] reds = new byte[size]; byte[] greens = new byte[size]; byte[] blues = new byte[size]; colorModel.getReds(reds); colorModel.getGreens(greens); colorModel.getBlues(blues); RGB[] rgbs = new RGB[size]; for (int i = 0; i < rgbs.length; i++) { rgbs[i] = new RGB(reds[i] & 0xFF, greens[i] & 0xFF, blues[i] & 0xFF); } PaletteData palette = new PaletteData(rgbs); ImageData data = new ImageData(bufferedImage.getWidth(), bufferedImage.getHeight(), colorModel.getPixelSize(), palette); data.transparentPixel = colorModel.getTransparentPixel(); WritableRaster raster = bufferedImage.getRaster(); int[] pixelArray = new int[1]; for (int y = 0; y < data.height; y++) { for (int x = 0; x < data.width; x++) { raster.getPixel(x, y, pixelArray); data.setPixel(x, y, pixelArray[0]); } } return data; } return null; }
From source file:de.mpg.imeji.logic.storage.util.ImageUtils.java
/** * cale the image if too big for the size * /*from www .ja v a 2s .c o m*/ * @param image * @param resolution * @return * @throws Exception */ public static BufferedImage scaleImage(BufferedImage image, FileResolution resolution) throws Exception { BufferedImage bufferedImage = null; int size = getResolution(resolution); if (image.getWidth() > size || image.getHeight() > size) { bufferedImage = scaleImageFast(image, size, resolution); } else { bufferedImage = image; } return bufferedImage; }
From source file:com.t3.image.ImageUtil.java
public static BufferedImage rgbToGrayscale(BufferedImage image) { if (image == null) { return null; }// www.j a va 2 s . c o m BufferedImage returnImage = new BufferedImage(image.getWidth(), image.getHeight(), pickBestTransparency(image)); for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { int encodedPixel = image.getRGB(x, y); int alpha = (encodedPixel >> 24) & 0xff; int red = (encodedPixel >> 16) & 0xff; int green = (encodedPixel >> 8) & 0xff; int blue = (encodedPixel) & 0xff; int average = (int) ((red + blue + green) / 3.0); // y = 0.3R + 0.59G + 0.11B luminance formula int value = (alpha << 24) + (average << 16) + (average << 8) + average; returnImage.setRGB(x, y, value); } } return returnImage; }
From source file:com.afis.jx.ckfinder.connector.utils.ImageUtils.java
/** * Uploads image and if the image size is larger than maximum allowed it resizes the image. * * @param stream input stream./* w w w . jav a 2s . co m*/ * @param file file name * @param fileName name of file * @param conf connector configuration * @throws IOException when error occurs. */ public static void createTmpThumb(final InputStream stream, final File file, final String fileName, final IConfiguration conf) throws IOException { BufferedInputStream bufferedIS = new BufferedInputStream(stream); bufferedIS.mark(Integer.MAX_VALUE); BufferedImage image = ImageIO.read(bufferedIS); if (image == null) { throw new IOException("Wrong file"); } Dimension dimension = createThumbDimension(image, conf.getImgWidth(), conf.getImgHeight()); if (dimension.width == 0 || dimension.height == 0 || (image.getHeight() == dimension.height && image.getWidth() == dimension.width)) { bufferedIS.reset(); writeUntouchedImage(bufferedIS, file); } else { resizeImage(image, dimension.width, dimension.height, conf.getImgQuality(), file); } stream.close(); }
From source file:com.github.zhanhb.ckfinder.connector.utils.ImageUtils.java
/** * create thumb file.//from w w w .j a va 2 s . c om * * @param originFile origin image file. * @param file file to save thumb * @param thumbnail connector thumbnail properties * @return true if success * @throws IOException when IO Exception occurs. */ public static boolean createThumb(Path originFile, Path file, ThumbnailProperties thumbnail) throws IOException { log.debug("createThumb"); BufferedImage image; try (InputStream is = Files.newInputStream(originFile)) { image = ImageIO.read(is); } if (image != null) { Dimension dimension = createThumbDimension(image, thumbnail.getMaxWidth(), thumbnail.getMaxHeight()); FileUtils.createPath(file, true); if (image.getHeight() <= dimension.height && image.getWidth() <= dimension.width) { writeUntouchedImage(originFile, file); } else { resizeImage(image, dimension.width, dimension.height, thumbnail.getQuality(), file); } return true; } else { log.error("Wrong image file"); } return false; }
From source file:de.darkblue.bongloader2.utils.ToolBox.java
public static BufferedImage grayScaleAlpha(BufferedImage original) { int alpha, red, green, blue; int newPixel; BufferedImage avg_gray = new BufferedImage(original.getWidth(), original.getHeight(), original.getType()); int[] avgLUT = new int[766]; for (int i = 0; i < avgLUT.length; i++) { avgLUT[i] = (int) (i / 3); }//w ww. j a v a2 s. c om for (int x = 0; x < original.getWidth(); x++) { for (int y = 0; y < original.getHeight(); y++) { // Get pixels by R, G, B int color = original.getRGB(x, y); alpha = color & 0xFF000000; red = (color >> 16) & 0xFF; green = (color >> 8) & 0xFF; blue = color & 0xFF; newPixel = red + green + blue; newPixel = avgLUT[newPixel]; // Return back to original format newPixel = newPixel | (newPixel << 8) | (newPixel << 16) | alpha; // Write pixels into image avg_gray.setRGB(x, y, newPixel); } } return avg_gray; }
From source file:com.zacwolf.commons.email.Email.java
public static BufferedImage makeRoundedBanner(BufferedImage image, int cornerRadius) { int w = image.getWidth(); int h = image.getHeight() + 10; BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = output.createGraphics(); g2.setComposite(AlphaComposite.Src); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.WHITE);//w w w . j a v a 2 s. com g2.fill(new RoundRectangle2D.Float(0, 0, w, h, cornerRadius, cornerRadius)); g2.setComposite(AlphaComposite.SrcAtop); g2.drawImage(image, 0, 0, null); g2.setComposite(AlphaComposite.SrcOver); // g2.setColor(new Color(153,153,153));//slight grey border // g2.drawRoundRect(0, 0, w-1, h, cornerRadius, cornerRadius); g2.dispose(); return output.getSubimage(0, 0, image.getWidth(), image.getHeight()); }
From source file:com.silverpeas.util.ImageUtil.java
public static String[] getWidthAndHeightByWidth(InputStream image, int widthParam) { String[] result = new String[2]; try {//ww w .ja v a 2 s . c om BufferedImage inputBuf = ImageIO.read(image); // calcul de la taille de la sortie double inputBufWidth; double inputBufHeight; double width; double ratio; double height; if (inputBuf.getWidth() > widthParam) { inputBufWidth = inputBuf.getWidth(); inputBufHeight = inputBuf.getHeight(); width = widthParam; ratio = inputBufWidth / width; height = inputBufHeight / ratio; } else { width = inputBuf.getWidth(); height = inputBuf.getHeight(); } String sWidth = Double.toString(width); String sHeight = Double.toString(height); result[0] = sWidth.substring(0, sWidth.indexOf('.')); result[1] = sHeight.substring(0, sHeight.indexOf('.')); return result; } catch (Exception e) { if (image != null) { SilverTrace.error("util", "ImageUtil.getWidthAndHeightByWidth", "root.MSG_GEN_ERROR", e); } } result[0] = ""; result[1] = ""; return result; }