bufferedimage

Exporting a JPanel to an image

怎甘沉沦 提交于 2019-11-26 18:24:55
问题 So I've been trying to export an image that I've drawn on a JPanel into an image. I've been using this method: BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); paint(g); try { ImageIO.write(image, "png", new File([location goes here]); } catch (IOException e) {} I get an image in my intended location but I get a compressed version of what my JPanel shows. The same happens if I try to export a BMP as well. Is

Java BufferedImage to PNG format Base64 String

☆樱花仙子☆ 提交于 2019-11-26 18:23:49
问题 I'm trying to get a screenshot output as a base64 encoded string but not getting very far. The code I have so far uses a Base64 library ( http://iharder.sourceforge.net/current/java/base64/ ): Robot robot = new Robot(); Rectangle r = new Rectangle( Toolkit.getDefaultToolkit().getScreenSize() ); BufferedImage bi = robot.createScreenCapture(r); ByteArrayOutputStream os = new ByteArrayOutputStream(); OutputStream b64 = new Base64.OutputStream(os); ImageIO.write(bi, "png", os);

Colorizing images in Java

蹲街弑〆低调 提交于 2019-11-26 17:17:20
问题 I'm working on some code to colorize an image in Java. Basically what I'd like to do is something along the lines of GIMP's colorize command, so that if I have a BufferedImage and a Color, I can colorize the Image with the given color. Anyone got any ideas? My current best guess at doing something like this is to get the rgb value of each pixel in the BufferedImage and add the RGB value of the Color to it with some scaling factor. 回答1: I have never used GIMP's colorize command. However, if

How to draw an image over another image?

旧时模样 提交于 2019-11-26 15:31:35
I have a Java project that's about traffic network simulation in a random city, I've managed to figure out a way to implement this project, so I divided each intersection into a section which is basically an extended JPanel class (named Carrefour)...everything works well until I got stuck with how to draw vehicles and make them pass through roads. So my problem is how to draw an image (vehicle image) over an another image (road)? If this is Swing, then draw the background image in a BufferedImage. Display this BufferedImage in a JComponent's (such as a JPanel's) paintComponent method using

Convert each animated GIF frame to a separate BufferedImage

依然范特西╮ 提交于 2019-11-26 15:24:18
I want to be able to take an animated GIF as input, count the frames (and perhaps other metadata), and convert each to a BufferedImage . How can I do this? Runtherisc If you want all the frames to be the same size (for optimized GIFs) try something like this: try { String[] imageatt = new String[]{ "imageLeftPosition", "imageTopPosition", "imageWidth", "imageHeight" }; ImageReader reader = (ImageReader)ImageIO.getImageReadersByFormatName("gif").next(); ImageInputStream ciis = ImageIO.createImageInputStream(new File("house2.gif")); reader.setInput(ciis, false); int noi = reader.getNumImages

Java - resize image without losing quality

被刻印的时光 ゝ 提交于 2019-11-26 15:06:35
问题 I have 10,000 photos that need to be resized so I have a Java program to do that. Unfortunately, the quality of the image is poorly lost and I don't have access to the uncompressed images. import java.awt.Graphics; import java.awt.AlphaComposite; import java.awt.Graphics2D; import java.awt.Image; import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; /** * This class will resize all the images in a

BufferedImage in Android

。_饼干妹妹 提交于 2019-11-26 14:39:19
问题 I've an app that takes a camera picture and saves on sdcard as jpeg. i want to distort the picture with a spherize filter. I can read the jpeg to a bitmap, but the code i have found that does the distortion distorts a bufferedimage. i understand that javax.imageio is not supported in android but is there a way of reading a jpeg into the memory as a bufferedimage? thanks mat. /* Copyright 2006 Jerry Huxtable Licensed under the Apache License, Version 2.0 (the "License"); you may not use this

Re-sizing an image without losing quality

 ̄綄美尐妖づ 提交于 2019-11-26 12:39:13
问题 I made this code to resize images with two factors. It works, but the quality of image is very bad after it is resized! Can you help me? This is the code public class ImageTest { private static final int factor1 = 3; private static final int factor2 = 4; public static void main(String [] args){ JFileChooser cs = new JFileChooser(); cs.setFileSelectionMode(cs.DIRECTORIES_ONLY); int i = cs.showOpenDialog(null); if(i==cs.APPROVE_OPTION){ File f = cs.getSelectedFile(); File[] ff = f.listFiles();

How to save a BufferedImage as a File

六眼飞鱼酱① 提交于 2019-11-26 12:38:03
问题 I am using the imgscalr Java library to resize an image . The result of a resize() method call is a BufferedImage object. I now want to save this as a file (usually .jpg). How can I do that? I want to go from BufferedImage -> File but perhaps this is not the correct approach? 回答1: File outputfile = new File("image.jpg"); ImageIO.write(bufferedImage, "jpg", outputfile); 回答2: You can save a BufferedImage object using write method of the javax.imageio.ImageIO class. The signature of the method

How to check a uploaded file whether it is an image or other file?

邮差的信 提交于 2019-11-26 12:21:35
问题 In my web application I have an image uploading module. I want to check the uploaded file whether it\'s an image file or any other file. I am using Java in server side. The image is read as BufferedImage in java and then I am writing it to disk with ImageIO.write() How shall I check the BufferedImage , whether it\'s really an image or something else? Any suggestions or links would be appreciated. 回答1: I'm assuming that you're running this in a servlet context. If it's affordable to check the