List of usage examples for java.awt.image BufferedImage getWidth
public int getWidth()
From source file:de.ailis.wlandsuite.image.PaletteImage.java
/** * Creates a diff between this picture and the specified one and returns it * in form of a transparent ega image.//from w ww. j a va2s .c om * * @param image * The other image to create a diff for * @return The diff as a transparent EGA image */ public TransparentEgaImage getDiff(final BufferedImage image) { final int aw = getWidth(); final int ah = getHeight(); final int bw = image.getWidth(); final int bh = image.getHeight(); final TransparentEgaImage diff = new TransparentEgaImage(bw, bh); for (int y = 0; y < bh; y++) { for (int x = 0; x < bw; x++) { if (y >= ah || x >= aw || getRGB(x, y) != image.getRGB(x, y)) diff.setRGB(x, y, image.getRGB(x, y)); } } return diff; }
From source file:org.shredzone.cilla.admin.AbstractImageBean.java
/** * Scales a {@link BufferedImage} to the given size, keeping the aspect ratio. If the * image is smaller than the resulting size, it will be magnified. * * @param image/*from w ww . ja v a 2 s .c om*/ * {@link BufferedImage} to scale * @param width * Maximum result width * @param height * Maximum result height * @return {@link BufferedImage} with the scaled image */ private BufferedImage scale(BufferedImage image, int width, int height) { ImageObserver observer = null; Image scaled = null; if (image.getWidth() > image.getHeight()) { scaled = image.getScaledInstance(width, -1, Image.SCALE_SMOOTH); } else { scaled = image.getScaledInstance(-1, height, Image.SCALE_SMOOTH); } BufferedImage result = new BufferedImage(scaled.getWidth(observer), scaled.getHeight(observer), BufferedImage.TYPE_INT_RGB); result.createGraphics().drawImage(scaled, 0, 0, observer); return result; }
From source file:SplashScreen.java
public SplashScreen(final BufferedImage img) { JPanel panel = new JPanel() { public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); g2d.drawImage(img, 0, 0, img.getWidth(), img.getHeight(), SplashScreen.this); }//from w w w .j a v a 2 s.co m }; panel.setPreferredSize(new Dimension(img.getWidth(), img.getHeight())); Container content = getContentPane(); content.setLayout(new BorderLayout()); content.add(panel, BorderLayout.NORTH); content.add(label = new JLabel(), BorderLayout.CENTER); content.add(bar = new JProgressBar(), BorderLayout.SOUTH); pack(); setLocationRelativeTo(null); }
From source file:de.anycook.upload.UploadHandler.java
/** * speichert eine grosse Version des Bildes * * @param image BufferedImage//w w w.j a v a 2 s .c o m * @param filename Name der zu erzeugenden Datei */ private void saveBigImage(BufferedImage image, String filename) throws IOException { int height = image.getHeight(); int width = image.getWidth(); int newWidth = bigWidth; int newHeight = new Double(((double) height / (double) width) * newWidth).intValue(); if (bigHeight > -1 && newHeight > bigHeight) { newHeight = bigHeight; newWidth = new Double(((double) width / (double) height) * newHeight).intValue(); } BufferedImage newImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB); newImage.getGraphics().drawImage(image.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH), 0, 0, null); imageSaver.save("big/", filename, newImage); }
From source file:bjerne.gallery.service.impl.ImageResizeServiceImpl.java
@Override public void resizeImage(File origImage, File newImage, int width, int height) throws IOException { LOG.debug("Entering resizeImage(origImage={}, width={}, height={})", origImage, width, height); long startTime = System.currentTimeMillis(); InputStream is = new BufferedInputStream(new FileInputStream(origImage)); BufferedImage i = ImageIO.read(is); IOUtils.closeQuietly(is);//ww w .j av a 2s. c o m BufferedImage scaledImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); int origWidth = i.getWidth(); int origHeight = i.getHeight(); LOG.debug("Original size of image - width: {}, height={}", origWidth, height); float widthFactor = ((float) origWidth) / ((float) width); float heightFactor = ((float) origHeight) / ((float) height); float maxFactor = Math.max(widthFactor, heightFactor); int newHeight, newWidth; if (maxFactor > 1) { newHeight = (int) (((float) origHeight) / maxFactor); newWidth = (int) (((float) origWidth) / maxFactor); } else { newHeight = origHeight; newWidth = origWidth; } LOG.debug("Size of scaled image will be: width={}, height={}", newWidth, newHeight); int startX = Math.max((width - newWidth) / 2, 0); int startY = Math.max((height - newHeight) / 2, 0); Graphics2D scaledGraphics = scaledImage.createGraphics(); scaledGraphics.setColor(backgroundColor); scaledGraphics.fillRect(0, 0, width, height); scaledGraphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); scaledGraphics.drawImage(i, startX, startY, newWidth, newHeight, null); OutputStream resultImageOutputStream = new BufferedOutputStream(FileUtils.openOutputStream(newImage)); String extension = FilenameUtils.getExtension(origImage.getName()); ImageIO.write(scaledImage, extension, resultImageOutputStream); IOUtils.closeQuietly(resultImageOutputStream); long duration = System.currentTimeMillis() - startTime; LOG.debug("Time in milliseconds to scale {}: {}", newImage.toString(), duration); }
From source file:de.anycook.upload.UploadHandler.java
/** * speichert eine kleine Version des Bildes * * @param image BufferedImage/*w w w .j a va2s . c om*/ * @param filename Name der zu erzeugenden Datei */ private void saveSmallImage(BufferedImage image, String filename) throws IOException { int height = image.getHeight(); int width = image.getWidth(); double imageRatio = (double) width / (double) height; int xtranslate = 0; int ytranslate = 0; if (imageRatio > 1) { xtranslate = (width - height) / 2; } else { ytranslate = (height - width) / 2; } BufferedImage tempImage = image.getSubimage(xtranslate, ytranslate, width - xtranslate * 2, height - ytranslate * 2); BufferedImage newImage = new BufferedImage(smallSize, smallSize, BufferedImage.TYPE_INT_RGB); newImage.getGraphics().drawImage(tempImage.getScaledInstance(smallSize, smallSize, Image.SCALE_SMOOTH), 0, 0, null); imageSaver.save("small/", filename, newImage); }
From source file:javafx1.Testpics.java
private void bildSchleife() { File f = new File("F:/NetBeansProjekte/pictures"); File[] fileArray = f.listFiles(); java.util.Arrays.sort(fileArray); for (File file : fileArray) { try {//from w ww .jav a2 s . c om System.out.println("file: " + file.getCanonicalPath()); File outputfile = new File(file.getCanonicalPath() + ".jpg"); BufferedImage bi = ImageIO.read(file); System.out.println(" enc" + encodeToString(bi, "jpg")); ImageIO.write(bi, "jpg", outputfile); bi = ImageIO.read(outputfile); System.out.println(" w" + bi.getWidth() + " h" + bi.getHeight()); byte[] data = ((DataBufferByte) bi.getRaster().getDataBuffer()).getData(); // System.out.println(new String(data)); byte[] x = Base64.encodeBase64URLSafe(data); System.out.println("x" + new String(x)); String b64 = Base64.encodeBase64String(data); System.out.println("64" + b64); // byte[] backToBytes = Base64.decodeBase64(base64String); // InputStream in = new ByteArrayInputStream(backToBytes); // BufferedImage bi; // bi = ImageIO.read(in); //byte[] xx = base64String.getBytes(StandardCharsets.UTF_8); // bild, wie es von http kommt // RunPic rp = new RunPic(this, data); // Platform.runLater(rp); try { Thread.sleep(50); break; } catch (InterruptedException ex) { Logger.getLogger(JavaFX1.class.getName()).log(Level.SEVERE, null, ex); } } catch (IOException ex) { Logger.getLogger(JavaFX1.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.epam.ta.reportportal.core.user.impl.EditUserHandler.java
private void validatePhoto(MultipartFile file) throws IOException { expect(file.getSize() < MAX_PHOTO_SIZE, equalTo(true)).verify(BINARY_DATA_CANNOT_BE_SAVED, "Image size should be less than 1 mb"); MediaType mediaType = new AutoDetectParser().getDetector().detect(TikaInputStream.get(file.getBytes()), new Metadata()); String subtype = mediaType.getSubtype(); expect(ImageFormat.fromValue(subtype), notNull()).verify(BINARY_DATA_CANNOT_BE_SAVED, "Image format should be " + ImageFormat.getValues()); BufferedImage read = ImageIO.read(file.getInputStream()); expect((read.getHeight() <= MAX_PHOTO_HEIGHT) && (read.getWidth() <= MAX_PHOTO_WIDTH), equalTo(true)) .verify(BINARY_DATA_CANNOT_BE_SAVED, "Image size should be 300x500px or less"); }
From source file:ch.admin.isb.hermes5.util.ImageUtilsTest.java
@Test public void testScaleByHeight() { byte[] gifStream = getResourceAsStream("logo.jpg"); BufferedImage bufferedImage = imageUtil.toBufferedImage(gifStream); BufferedImage makeSmallerToMax = imageUtil.makeSmallerToMax(bufferedImage, 200, 50); assertEquals(50, makeSmallerToMax.getHeight()); assertEquals((int) (50.0 * bufferedImage.getWidth() / bufferedImage.getHeight()) + 1 /*RUNDUNGSFEHLER*/, makeSmallerToMax.getWidth()); }
From source file:org.esa.beam.visat.toolviews.stat.XYImagePlot.java
public void setImage(BufferedImage image) { synchronized (imageLock) { this.image = image; if (image != null && imageDataBounds == null) { setImageDataBounds(new Rectangle(0, 0, image.getWidth(), image.getHeight())); }// w w w . j a v a 2s .c om } }