bufferedimage

How do I desaturate a BufferedImage in Java?

雨燕双飞 提交于 2019-12-01 03:14:29
问题 What's the simplest way to desaturate a BufferedImage ? 回答1: Use ColorConvertOp: public static BufferedImage desaturate(BufferedImage source) { ColorConvertOp colorConvert = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); colorConvert.filter(source, source); return source; } Update : There is indeed a simpler way. You can use the GrayFilter class. What's nice about this class is that it provides a static utility method (i.e. createDisabledImage(Image i) ) that will

Set BufferedImage to be a color in Java

故事扮演 提交于 2019-12-01 02:46:24
I need to create a rectangular BufferedImage with a specified background color, draw some pattern on the background and save it to file. I don't know how to create the background. I am using a nested loop: BufferedImage b_img = ... for every row for every column setRGB(r,g,b); But it's very slow when the image is large. How to set the color in a more efficient way? Get the graphics object for the image, set the current paint to the desired colour, then call fillRect(0,0,width,height) . BufferedImage b_img = ... Graphics2D graphics = b_img.createGraphics(); graphics.setPaint ( new Color ( r, g,

How do I get the X and Y location of an image in a JScrollPane

孤街浪徒 提交于 2019-12-01 01:57:31
I am trying to make a Map Editor for a 2D RPG, and what I currently am trying to do (to place tiles on the ground) is to have a JScrollPane with a JLabel (that has an image in it) and a Mouse Listener attached to the JScrollPane to determine the X and Y location of the image. The problem I run into is that it doesn't get the Images X and Y location but the JScrollPanes X and Y location. So I have a JScrollPane attached to an Image that is 512x4928, I attached a mouse listener to it. the problem resides when I try to get the Y location, since JScrollPane is a separate object it gets the X and Y

how do I scale a BufferedImage

拜拜、爱过 提交于 2019-12-01 01:55:06
问题 I have viewed this question, but it does not seem to actually answer the question that I have. I have a, image file, that may be any resolution. I need to load that image into a BufferedImage Object at a specific resolution (say, for this example, 800x800). I know the Image class can use getScaledInstance() to scale the image to a new size, but I then cannot figure out how to get it back to a BufferedImage . Is there a simple way to scale a Buffered Image to a specific size? NOTE I I do not

Creating a BufferedImage causes GLFW in the LWJGL to lock up (Java)

我的未来我决定 提交于 2019-12-01 01:39:46
There is a link to download the project below. The project already contains the LWJGL. Just open it with eclipse and tell me I'm not going crazy I'm experimenting with the LWJGL for the first time and have managed to get the sample code on the LWJGL website to work. The odd thing is, if I create an instance of a BufferedImage anywhere in the program, it causes the whole thing to lock up. I've managed to narrow it down to the ColorModel class (which is used by BufferedImage) but can't figure out why it is happening. I'll attach a zip file with my eclipse project to this post which demonstrates

Serializing an object that includes BufferedImages

天涯浪子 提交于 2019-12-01 01:32:56
As the title suggests, I'm trying to save to file an object that contains (among other variables, Strings, etc) a few BufferedImages. I found this: How to serialize an object that includes BufferedImages And it works like a charm, but with a small setback: it works well if your object contains only ONE image. I've been struggling to get his solution to work with more than one image (which in theory should work) but each time I read the file in, I get my object back, I get the correct number of images, but only the first image actually gets read in; the others are just null images that have no

Converting BufferedImage to Mat (OpenCV) in Java [duplicate]

核能气质少年 提交于 2019-12-01 00:45:48
This question already has an answer here: Converting BufferedImage to Mat in opencv 7 answers I've tried this link and have the code below. My program imports images in a BufferedImage format and then displays it to the users. I'm using the matchingTemplate function in OpenCV which requires me to convert it to a Mat format. The code works if I import the image -> convert it to Mat then save the image using imwrite. The program also allows the user to crop an image and then use the Template matching to compare it to another image. The issue come when I tried to convert the cropped image to Mat

How do I create a BufferedImage from array containing pixels?

前提是你 提交于 2019-12-01 00:44:09
I get the pixels from BufferedImage using the method getRGB() . The pixels are stored in array called data[] . After some manipulation on data array, I need to create a BufferedImage again so that I can pass it to a module which will display the modified image, from this data array, but I am stuck with it. BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Then set the pixels again. bufferedImage.setRGB(x, y, your_value); PS: as stated in the comments, please use the answer from @TacticalCoder I get the pixels from the BufferedImage using the method

BufferedImage & createScreenCapture produces wrong colors

不打扰是莪最后的温柔 提交于 2019-11-30 22:22:30
In my Java program I need to analyze a color of a pixel in given coordinates. Because of the fact that I need to do it often, first I capture a part of the screen, and then get a pixel color. I am doing this with: BufferedImage bi = robot.createScreenCapture(new Rectangle(0,0,100,100)); ... pxcolor = GetPixelColor(bi,x,y); ... ImageIO.write(bi, "bmp", new File("myScreenShot.bmp")); The GetPixelColor function is quite obvious: public Color GetPixelColor(BufferedImage b, int x, int y) { int pc = b.getRGB(x, y); Color ccc = new Color(pc,true); int red = (pc & 0x00ff0000) >> 16; // for testing int

How to change the contrast and brightness of an image stored as pixel values

隐身守侯 提交于 2019-11-30 22:17:00
I have an image that is stored as an array of pixel values. I want to be able to apply a brightness or contrast filter to this image. Is there any simple way, or algorithm, that I can use to achieve this. Here is my code... PlanarImage img=JAI.create("fileload","C:\\aimages\\blue_water.jpg"); BufferedImage image = img.getAsBufferedImage(); int w = image.getWidth(); int h = image.getHeight(); int k = 0; int[] sbins = new int[256]; int[] pixel = new int[3]; Double d = 0.0; Double d1; for (int x = 0; x < bi.getWidth(); x++) { for (int y = 0; y < bi.getHeight(); y++) { pixel = bi.getRaster()