bufferedimage

Understanding BufferedImage.getRGB output values

喜你入骨 提交于 2019-11-27 20:25:13
I'm getting an integer value for the pixel in an image using this method: int colour = img.getRGB(x, y); Then I'm printing out the values and I see that black pixels correspond to a value like "-16777216", a kind of blue to something like "-16755216", etc. Can someone please explain me the logic behind this value? afzalex getRGB(int x, int y) return you the value of color pixel at location (x,y) . You are misinterpreting the returned value. It is in the binary format. like 11...11010101 and that is given to you as int value. If you want to get RGB (i.e. Red, Green, Blue) components of that

Get RGB of a BufferedImage

二次信任 提交于 2019-11-27 20:10:07
Can anybody explain how to get an array of rgb value from a BufferedImage? I have a grey scale image in a BufferedImage and need to extract an array of 0 to 255 values that describe the image. I know the BufferedImage is correct because I can save it to PNG. However, if I use int[] dataBuffInt = ((DataBufferInt) heightMap.getDataBuffer()).getData(); I get a bunch of huge negative numbers. I have searched for a while and seen some references to shifting some values ( post ) but don't really understand what they are saying. Basically I want to go from a BufferedImage to an array of 0 to 255 RBG

Getting pixel RGB from a bufferedImage from the mouses X and Y position

久未见 提交于 2019-11-27 19:21:53
问题 I am making a color chooser program with an image. The program first loads in the image and then when you hover over the image, it will get the current pixels RGB value off of the mouses X and Y position. I have set up the frame and loaded them image, can someone help me get it working with the pixels? package net.ogpc.settings; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.image.BufferedImage; import javax.imageio.ImageIO; import javax.swing.ImageIcon

How do I properly load a BufferedImage in java?

若如初见. 提交于 2019-11-27 17:05:53
问题 Okay, so I've been trying to load a BufferedImage using this code: URL url = this.getClass().getResource("test.png"); BufferedImage img = (BufferedImage) Toolkit.getDefaultToolkit().getImage(url); This gives me a type cast error when I run it though, so how do I properly load a BufferedImage? 回答1: Use ImageIO.read() instead: BufferedImage img = ImageIO.read(url); 回答2: BufferedImage img = null; try { img = ImageIO.read(new File("D:\\work\\files\\logo.jpg")); } catch (IOException e) { // TODO

Java - resize image without losing quality

主宰稳场 提交于 2019-11-27 16:50:27
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 given folder * @author * */ public class JavaImageResizer { public static void main(String[] args) throws

Colorizing images in Java

两盒软妹~` 提交于 2019-11-27 15:47:25
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. Bernie Perez I have never used GIMP's colorize command. However, if your getting the RGB value of each pixel and adding RGB value to it you should really use a

Load Java Image inside package from a class in a different package

二次信任 提交于 2019-11-27 14:59:30
问题 I have a Java project called MyProject. I have a few different packages (keeping names simple for the purpose of this question), as follows: src/PackageA src/PackageA/PackageAa src/PackageA/PackageAa/PackageAaa src/PackageB src/PackageB/PackageBa src/PackageB/PackageBa/PackageBaa I have a class src/PackageA/PackageAa/PackageAaa/MyJavaFile.java And I have an image src/PackageB/PackageBa/PackageBaa/MyImage.png Inside of MyJavaFile.java , I would like to declare an Image oject of MyImage.png

How to read pixel color in a java BufferedImage with transparency

蓝咒 提交于 2019-11-27 14:56:37
问题 I am reading pixel color in a BufferedImage as follows: ..... InputStream is = new BufferedInputStream(conn.getInputStream()); BufferedImage image = ImageIO.read(is); int color = image.getRGB(x, y); int red = (colour & 0x00ff0000) >> 16; int green = (colour & 0x0000ff00) >> 8; int blue = colour & 0x000000ff; Now this works fine except for png's with transparency. I find that if x,y refer to a transparent pixel with no color, i still read a color, generally the same color as used elsewhere in

How to convert BufferedImage to image to display on JSP

与世无争的帅哥 提交于 2019-11-27 14:51:57
I would like to convert BufferedImage to an image that will display on JSP page. How can I achieve this? BalusC First, JSP is a view technology providing a template to write HTML/CSS/JS in and the ability to interact with backend Java code to control page flow and access backend data. Your problem is more in HTML. Now, to display an image in a HTML page, you need the HTML <img> element. To define/allocate an image, you just have to let the src attribute point to an URL. E.g. <img src="url/to/image.jpg"> (it can be either relative to the current context, or an absolute URL, e.g. starting with

Converting a series of BufferedImages to a video in Java?

前提是你 提交于 2019-11-27 13:57:29
问题 How would I convert an an array of BufferedImages into a video? I'm making a screen recorder. How would I compress the video afterward? 回答1: You can use Xuggler (on Windows, Mac or Linux) to do this, and the following tutorials will show you exactly how to do it. In particular, see the (I'm not kidding) "How to Grow Some Balls" tutorial for a program that makes a video out of a series of BufferedImages (and some audio). 回答2: You'll need the JMF (Java Media Framework) API for this. Sun has a