List of usage examples for java.awt.image BufferedImage getHeight
public int getHeight()
From source file:com.aimluck.eip.fileupload.util.FileuploadUtils.java
/** * ???????// w ww . j a v a 2 s .com * * @param org_id * @param folderName * @param uid * @param fileBean * @param acceptExts * @param msgList * @return */ public static ShrinkImageSet getBytesShrinkFilebean(String org_id, String folderName, int uid, FileuploadLiteBean fileBean, String[] acceptExts, int width, int height, List<String> msgList, boolean isFixOrgImage) { byte[] result = null; byte[] fixResult = null; InputStream is = null; boolean fixed = false; try { String file_name = fileBean.getFileName(); String ext = ""; if (acceptExts != null && acceptExts.length > 0) { // ??? // ???? boolean isAccept = false; String tmpExt = null; int len = acceptExts.length; for (int i = 0; i < len; i++) { if (!acceptExts[i].startsWith(".")) { tmpExt = "." + acceptExts[i]; } if (file_name.toLowerCase().endsWith(tmpExt)) { isAccept = true; ext = tmpExt.replace(".", ""); ; break; } } if (!isAccept) { // ???????null ? return null; } } is = ALStorageService.getFile(FOLDER_TMP_FOR_ATTACHMENT_FILES, uid + ALStorageService.separator() + folderName, String.valueOf(fileBean.getFileId())); byte[] imageInBytes = IOUtils.toByteArray(is); ImageInformation readImageInformation = readImageInformation(new ByteArrayInputStream(imageInBytes)); BufferedImage bufferdImage = ImageIO.read(new ByteArrayInputStream(imageInBytes)); if (readImageInformation != null) { bufferdImage = transformImage(bufferdImage, getExifTransformation(readImageInformation), readImageInformation.orientation >= 5 ? bufferdImage.getHeight() : bufferdImage.getWidth(), readImageInformation.orientation >= 5 ? bufferdImage.getWidth() : bufferdImage.getHeight()); fixed = isFixOrgImage; } if (bufferdImage == null) { // ?bufferdImage???????????,null?. return null; } BufferedImage shrinkImage = FileuploadUtils.shrinkAndTrimImage(bufferdImage, width, height); Iterator<ImageWriter> writers = ImageIO.getImageWritersBySuffix("jpeg"); ImageWriter writer = writers.next(); ByteArrayOutputStream out = new ByteArrayOutputStream(); ImageOutputStream ios = ImageIO.createImageOutputStream(out); writer.setOutput(ios); writer.write(shrinkImage); result = out.toByteArray(); if (fixed) { Iterator<ImageWriter> writers2 = ImageIO.getImageWritersBySuffix(ext); ImageWriter writer2 = writers2.next(); ByteArrayOutputStream out2 = new ByteArrayOutputStream(); ImageOutputStream ios2 = ImageIO.createImageOutputStream(out2); writer2.setOutput(ios2); writer2.write(bufferdImage); fixResult = out2.toByteArray(); } } catch (Exception e) { logger.error("fileupload", e); result = null; } finally { try { if (is != null) { is.close(); } } catch (Exception e) { logger.error("fileupload", e); result = null; } } return new ShrinkImageSet(result, fixed ? fixResult : null); }
From source file:com.actelion.research.orbit.imageAnalysis.utils.ImageUtils.java
/** * Rescales using arbitrary intensities and converts to 8bit. Works for gray- and rgb color images. * * @param bi16//ww w . j a v a2 s .c om * @return */ public static BufferedImage convertTo8bit(BufferedImage bi16, double intScalingMin, double intScalignMax) { // TODO: use min,max from plate meta data, not image specific int[][] minMax = ImageUtils.getMinMaxIntensitiesOfBI(bi16); BufferedImage bi = null; if (bi16.getSampleModel().getNumBands() == 1) { bi16 = ImageUtils.scaleIntensities(bi16, getPercentileIntensity(bi16, intScalingMin), getPercentileIntensity(bi16, intScalignMax)); bi = new BufferedImage(bi16.getWidth(), bi16.getHeight(), BufferedImage.TYPE_BYTE_GRAY); } else if (bi16.getSampleModel().getNumBands() == 3) { bi16 = ImageUtils.scaleIntensities(bi16, getPercentileIntensity(bi16, intScalingMin), getPercentileIntensity(bi16, intScalignMax)); bi = new BufferedImage(bi16.getWidth(), bi16.getHeight(), BufferedImage.TYPE_INT_RGB); } else { throw new IllegalArgumentException( "Only images with 1 band (gray-color) or 3 bands (rgb) supported. This image has " + bi16.getSampleModel().getNumBands() + " bands."); } Graphics2D g2d = bi.createGraphics(); g2d.drawImage(bi16, 0, 0, null); g2d.dispose(); return bi; }
From source file:GraphicsUtil.java
/** * Copies data from one bufferedImage to another paying attention * to the state of AlphaPreMultiplied./*from w ww . ja v a 2 s .c om*/ * * @param src The source * @param dst The destination */ public static void copyData(BufferedImage src, BufferedImage dst) { Rectangle srcRect = new Rectangle(0, 0, src.getWidth(), src.getHeight()); copyData(src, srcRect, dst, new Point(0, 0)); }
From source file:de.uniwue.dmir.heatmap.util.beans.RangeFactoryBean.java
public RangeFactoryBean(double min, double max, BufferedImage image) { this(min, max, image.getHeight()); }
From source file:net.pms.util.UMSUtils.java
@SuppressWarnings("deprecation") public static InputStream scaleThumb(InputStream in, RendererConfiguration r) throws IOException { if (in == null) { return in; }//from www .j av a 2 s . c o m String ts = r.getThumbSize(); if (StringUtils.isEmpty(ts) && StringUtils.isEmpty(r.getThumbBG())) { // no need to convert here return in; } int w; int h; Color col = null; BufferedImage img; try { img = ImageIO.read(in); } catch (Exception e) { // catch whatever is thrown at us // we can at least log it LOGGER.debug("couldn't read thumb to manipulate it " + e); img = null; // to make sure } if (img == null) { return in; } w = img.getWidth(); h = img.getHeight(); if (StringUtils.isNotEmpty(ts)) { // size limit thumbnail w = getHW(ts.split("x"), 0); h = getHW(ts.split("x"), 1); if (w == 0 || h == 0) { LOGGER.debug("bad thumb size {} skip scaling", ts); w = h = 0; // just to make sure } } if (StringUtils.isNotEmpty(r.getThumbBG())) { try { Field field = Color.class.getField(r.getThumbBG()); col = (Color) field.get(null); } catch (Exception e) { LOGGER.debug("bad color name " + r.getThumbBG()); } } if (w == 0 && h == 0 && col == null) { return in; } ByteArrayOutputStream out = new ByteArrayOutputStream(); BufferedImage img1 = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g = img1.createGraphics(); if (col != null) { g.setColor(col); } g.fillRect(0, 0, w, h); g.drawImage(img, 0, 0, w, h, null); ImageIO.write(img1, "jpeg", out); out.flush(); return new ByteArrayInputStream(out.toByteArray()); }
From source file:ImageOpByRomain.java
/** * <p>//from w w w . ja v a2s. c o m * Returns a thumbnail of a source image. * </p> * <p> * This method favors speed over quality. When the new size is less than half * the longest dimension of the source image, * {@link #createThumbnail(BufferedImage, int)} or * {@link #createThumbnail(BufferedImage, int, int)} should be used instead to * ensure the quality of the result without sacrificing too much performance. * </p> * * @see #createThumbnailFast(java.awt.image.BufferedImage, int) * @see #createThumbnail(java.awt.image.BufferedImage, int) * @see #createThumbnail(java.awt.image.BufferedImage, int, int) * @param image * the source image * @param newWidth * the width of the thumbnail * @param newHeight * the height of the thumbnail * @return a new compatible <code>BufferedImage</code> containing a * thumbnail of <code>image</code> * @throws IllegalArgumentException * if <code>newWidth</code> is larger than the width of * <code>image</code> or if code>newHeight</code> is larger * than the height of <code>image</code> or if one of the * dimensions is <= 0 */ public static BufferedImage createThumbnailFast(BufferedImage image, int newWidth, int newHeight) { if (newWidth >= image.getWidth() || newHeight >= image.getHeight()) { throw new IllegalArgumentException( "newWidth and newHeight cannot" + " be greater than the image" + " dimensions"); } else if (newWidth <= 0 || newHeight <= 0) { throw new IllegalArgumentException("newWidth and newHeight must" + " be greater than 0"); } BufferedImage temp = createCompatibleImage(image, newWidth, newHeight); Graphics2D g2 = temp.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.drawImage(image, 0, 0, temp.getWidth(), temp.getHeight(), null); g2.dispose(); return temp; }
From source file:at.tuwien.ifs.somtoolbox.apps.viewer.fileutils.ExportUtils.java
public static void drawLinkInfo(GrowingLayer growingLayer, MapPNode mapPnode, double unitWidth, Graphics2D graphics, String dataFilesPrefix) { int width = (int) unitWidth; for (int x = 0; x < growingLayer.getXSize(); x++) { for (int y = 0; y < growingLayer.getYSize(); y++) { try { if (growingLayer.getUnit(x, y) != null) { String[] mappedData = growingLayer.getUnit(x, y).getMappedInputNames(); if (mappedData != null) { boolean hasValidLink = false; for (String element : mappedData) { if (new File(dataFilesPrefix + element).exists()) { hasValidLink = true; break; }/*from w w w.j ava2 s .c om*/ } if (hasValidLink) { try { BufferedImage icon = ImageIO.read(new FileInputStream(ExportUtils.class .getResource(RESOURCE_PATH_ICONS + "note.png").getFile())); // icon = scaleImageByHeight(icon, (int) (unitWidth - 2)); int iconHeight = (int) (unitWidth * 0.7); int iconWidth = (int) ((double) iconHeight / (double) icon.getHeight() * icon.getWidth()); int restWidth = (width - iconWidth) / 2; int restHeight = (width - iconHeight) / 2; graphics.drawImage(icon, x * width + restWidth, y * width + restHeight, iconWidth, iconHeight, null); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } } catch (LayerAccessException e) { // should not happen e.printStackTrace(); } } } }
From source file:TexturedText.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Font font = new Font("Times New Roman", Font.PLAIN, 72); g2.setFont(font);/*from ww w . j a va 2 s . c o m*/ String s = "Java Source and Support"; Dimension d = getSize(); float x = 20, y = 100; BufferedImage bi = getTextureImage(); Rectangle r = new Rectangle(0, 0, bi.getWidth(), bi.getHeight()); TexturePaint tp = new TexturePaint(bi, r); g2.setPaint(tp); g2.drawString(s, x, y); }
From source file:ImageOpByRomain.java
/** * <p>/*w w w . j a v a 2 s.c om*/ * Returns a thumbnail of a source image. <code>newSize</code> defines the * length of the longest dimension of the thumbnail. The other dimension is * then computed according to the dimensions ratio of the original picture. * </p> * <p> * This method offers a good trade-off between speed and quality. The result * looks better than * {@link #createThumbnailFast(java.awt.image.BufferedImage, int)} when the * new size is less than half the longest dimension of the source image, yet * the rendering speed is almost similar. * </p> * * @see #createThumbnailFast(java.awt.image.BufferedImage, int, int) * @see #createThumbnailFast(java.awt.image.BufferedImage, int) * @see #createThumbnail(java.awt.image.BufferedImage, int, int) * @param image * the source image * @param newSize * the length of the largest dimension of the thumbnail * @return a new compatible <code>BufferedImage</code> containing a * thumbnail of <code>image</code> * @throws IllegalArgumentException * if <code>newSize</code> is larger than the largest dimension * of <code>image</code> or <= 0 */ public static BufferedImage createThumbnail(BufferedImage image, int newSize) { int width = image.getWidth(); int height = image.getHeight(); boolean isWidthGreater = width > height; if (isWidthGreater) { if (newSize >= width) { throw new IllegalArgumentException("newSize must be lower than" + " the image width"); } } else if (newSize >= height) { throw new IllegalArgumentException("newSize must be lower than" + " the image height"); } if (newSize <= 0) { throw new IllegalArgumentException("newSize must" + " be greater than 0"); } float ratioWH = (float) width / (float) height; float ratioHW = (float) height / (float) width; BufferedImage thumb = image; do { if (isWidthGreater) { width /= 2; if (width < newSize) { width = newSize; } height = (int) (width / ratioWH); } else { height /= 2; if (height < newSize) { height = newSize; } width = (int) (height / ratioHW); } BufferedImage temp = createCompatibleImage(image, width, height); Graphics2D g2 = temp.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.drawImage(thumb, 0, 0, temp.getWidth(), temp.getHeight(), null); g2.dispose(); thumb = temp; } while (newSize != (isWidthGreater ? width : height)); return thumb; }
From source file:main.java.whiteSocket.Bloop.java
public static BufferedImage createWhiteImage() { BufferedImage testOut = new BufferedImage(Bloop.blooprint.getWidth(), Bloop.blooprint.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D graphics = testOut.createGraphics(); graphics.setPaint(Color.white); graphics.fillRect(0, 0, testOut.getWidth(), testOut.getHeight()); return testOut; }