List of usage examples for java.awt.image BufferedImage getType
public int getType()
From source file:de.bund.bfr.jung.JungUtils.java
private static Paint mixWith(Paint paint, Color mix) { if (paint instanceof Color) { Color c = (Color) paint; return new Color((c.getRed() + mix.getRed()) / 2, (c.getGreen() + mix.getGreen()) / 2, (c.getBlue() + mix.getBlue()) / 2, (c.getAlpha() + mix.getAlpha()) / 2); } else if (paint instanceof TexturePaint) { BufferedImage texture = ((TexturePaint) paint).getImage(); BufferedImage mixed = new BufferedImage(texture.getWidth(), texture.getHeight(), texture.getType()); for (int x = 0; x < texture.getWidth(); x++) { for (int y = 0; y < texture.getHeight(); y++) { mixed.setRGB(x, y, ((Color) mixWith(new Color(texture.getRGB(x, y)), mix)).getRGB()); }//from ww w.ja v a2 s . co m } return new TexturePaint(mixed, new Rectangle(mixed.getWidth(), mixed.getHeight())); } else { return paint; } }
From source file:es.logongas.util.seguridad.CodigoVerificacionSeguro.java
/** * Esta funcin se aplica pq para imagenes muy grandes no reconoce el cdigo * QR/*from ww w. j a v a2 s . com*/ * * @param originalImage La imagen original * @param f El factor de escalado * @return La iamgen reescalada. */ private static BufferedImage resizeImage(BufferedImage originalImage, double f) { int ancho = (int) (((double) originalImage.getWidth()) * f); int alto = (int) (((double) originalImage.getHeight()) * f); int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : originalImage.getType(); BufferedImage resizedImage = new BufferedImage(ancho, alto, type); Graphics2D g = resizedImage.createGraphics(); g.drawImage(originalImage, 0, 0, ancho, alto, null); g.dispose(); return resizedImage; }
From source file:com.fluidops.iwb.deepzoom.DZConvert.java
static int getType(BufferedImage img) { if (img.getType() == BufferedImage.TYPE_CUSTOM) return BufferedImage.TYPE_INT_ARGB_PRE; else//from w w w . j a v a2 s. c om return img.getType(); }
From source file:com.alvermont.terraj.stargen.ui.UIUtils.java
/** * Combine a list of images horizontally into one new image. * //from www . j a v a 2 s .c o m * @param images The list of images to be combined * @return A new image, as wide horizontally as the sum of the input images, * containing all the input images */ public static BufferedImage combineImagesHorizontal(List<BufferedImage> images) { int imageType = -1; int height = 0; int width = 0; // first work out the sizing and image type, we assume the images // are all compatible. for (BufferedImage image : images) { if (imageType == -1) { imageType = image.getType(); } width += image.getWidth(); height = Math.max(height, image.getHeight()); } // create the new image and clear it to black BufferedImage bi = new BufferedImage(width, height, imageType); Graphics2D g = bi.createGraphics(); g.setColor(Color.BLACK); g.fillRect(0, 0, width, height); // merge the images into the new one int xpos = 0; for (BufferedImage image : images) { int ypos = (height - image.getHeight()) / 2; g.drawImage(image, xpos, ypos, null); xpos += image.getWidth(); } return bi; }
From source file:com.fengduo.bee.service.impl.file.FileServiceImpl.java
/** * ?//from w ww.j av a2 s . c o m * * @param source * @param targetW * @param targetH * @param ifScaling ? * @return */ public static BufferedImage resize(BufferedImage source, int targetW, int targetH, boolean ifScaling) { // targetWtargetH int type = source.getType(); BufferedImage target = null; double sx = (double) targetW / source.getWidth(); double sy = (double) targetH / source.getHeight(); // targetWtargetH??,?if else??? if (ifScaling) { if (sx > sy) { sx = sy; targetW = (int) (sx * source.getWidth()); } else { sy = sx; targetH = (int) (sy * source.getHeight()); } } if (type == BufferedImage.TYPE_CUSTOM) { // handmade ColorModel cm = source.getColorModel(); WritableRaster raster = cm.createCompatibleWritableRaster(targetW, targetH); boolean alphaPremultiplied = cm.isAlphaPremultiplied(); target = new BufferedImage(cm, raster, alphaPremultiplied, null); } else target = new BufferedImage(targetW, targetH, type); Graphics2D g = target.createGraphics(); // smoother than exlax: g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.drawRenderedImage(source, AffineTransform.getScaleInstance(sx, sy)); g.dispose(); return target; }
From source file:com.reydentx.core.common.PhotoUtils.java
public static byte[] scaleBufferedImage(boolean isPNG, BufferedImage originalImage, int x, int y, int width, int height) { byte[] imageFinal = null; try {/* w ww . j ava2s. c om*/ if (originalImage != null) { int type = (originalImage.getType() == 0) ? BufferedImage.TYPE_INT_ARGB : originalImage.getType(); BufferedImage resizedImage = new BufferedImage(width, height, type); Graphics2D g = resizedImage.createGraphics(); ByteArrayOutputStream outstream = new ByteArrayOutputStream(); g.drawImage(originalImage, x, y, width, height, null); g.dispose(); if (isPNG) { ImageIO.write(resizedImage, "png", outstream); } else { ImageIO.write(resizedImage, "jpg", outstream); } imageFinal = outstream.toByteArray(); } } catch (IOException ex) { } return imageFinal; }
From source file:Main.java
/** * Rotates given image by given degrees which should be a multiple of 90 * @param source image to be rotated// w w w . java 2 s . com * @param degrees the angle by which to rotate, should be a multiple of 90 * @return the rotated image */ public static BufferedImage rotateByRightAngle(BufferedImage source, int degrees) { assert degrees % 90 == 0; degrees = degrees % 360; int w = source.getWidth(); int h = source.getHeight(); int w1, h1; switch (degrees) { case 90: case 270: w1 = h; h1 = w; break; default: w1 = w; h1 = h; } BufferedImage rotated = new BufferedImage(w1, h1, source.getType()); for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { int v = source.getRGB(x, y); int x1, y1; switch (degrees) { case 90: x1 = h - y - 1; y1 = x; break; case 180: x1 = w - x - 1; y1 = h - y - 1; break; case 270: x1 = y; y1 = w - x - 1; break; default: x1 = x; y1 = y; break; } rotated.setRGB(x1, y1, v); } } return rotated; }
From source file:ch.rasc.downloadchart.DownloadChartServlet.java
private static void writeImage(HttpServletResponse response, byte[] imageData, Integer width, Integer height, String formatName) throws IOException { BufferedImage originalImage = ImageIO.read(new ByteArrayInputStream(imageData)); Dimension newDimension = calculateDimension(originalImage, width, height); if (newDimension != null) { int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : originalImage.getType(); BufferedImage resizedImage = new BufferedImage(newDimension.width, newDimension.height, type); Graphics2D g = resizedImage.createGraphics(); g.drawImage(originalImage, 0, 0, newDimension.width, newDimension.height, null); g.dispose();/*from w w w . j ava 2 s. c o m*/ g.setComposite(AlphaComposite.Src); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); ImageIO.write(resizedImage, formatName, response.getOutputStream()); } else { if ("png".equals(formatName)) { response.getOutputStream().write(imageData); } else { ImageIO.write(originalImage, "gif", response.getOutputStream()); } } }
From source file:com.mikenimer.familydam.services.photos.ThumbnailService.java
/** * using the metadata orientation transformation information rotate the image. * @param image// w w w . jav a 2 s . c o m * @param transform * @return * @throws Exception */ public static BufferedImage transformImage(BufferedImage image, AffineTransform transform) throws Exception { AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BICUBIC); BufferedImage destinationImage = op.createCompatibleDestImage(image, (image.getType() == BufferedImage.TYPE_BYTE_GRAY) ? image.getColorModel() : null); Graphics2D g = destinationImage.createGraphics(); g.setBackground(Color.WHITE); g.clearRect(0, 0, destinationImage.getWidth(), destinationImage.getHeight()); destinationImage = op.filter(image, destinationImage); return destinationImage; }
From source file:cn.z.Ocr5.java
public static BufferedImage scaleImage(BufferedImage img) { final ScaleFilter sf = new ScaleFilter(16, 16); final BufferedImage imgdest = new BufferedImage(16, 16, img.getType()); return sf.filter(img, imgdest); }