bufferedimage

Convert Data-URL to BufferedImage

风流意气都作罢 提交于 2019-11-30 13:13:02
问题 I have a Data-URL from an image file and have to pass it through to another function. Along this path from Data-URL to the BufferedImage it needs to be a byteArray. my approach was the following: String dataUrl; byte[] imageData = dataUrl.getBytes(); // pass the byteArray along the path // create BufferedImage from byteArray BufferedImage inputImage = ImageIO.read(new ByteArrayInputStream(imageData)); // If the picture is null, then throw an unsupported image exception. if (inputImage == null

Java colour detection

自闭症网瘾萝莉.ら 提交于 2019-11-30 10:18:30
Im looking to implement a feature in Java which reads an image and is able to detect where there are shades of red, blue, green, yellow, etc. as part of a satellite image analysis program. So for example in a standard satellite image, blue would be water so I would like the program to read how many pixels are blue and then it could say x% of the image is water. I know it would be possible using a whole load of logic statements by reading the RGB value of each pixel but is there an easier way to do this? Otherwise there will be hundreds of if statements which is going to take a long time to

Create a buffered image from rgb pixel values

折月煮酒 提交于 2019-11-30 09:55:37
I have an integer array of RGB pixels that looks something like: pixels[0] = <rgb-value of pixel(0,0)> pixels[1] = <rgb-value of pixel(1,0)> pixels[2] = <rgb-value of pixel(2,0)> pixels[3] = <rgb-value of pixel(0,1)> ...etc... And I'm trying to create a BufferedImage from it. I tried the following: BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); img.getRaster().setPixels(0, 0, width, height, pixels); But the resulting image has problems with the color bands. The image is unclear and there are diagonal and horizontal lines through it. What is the proper way to

Save image from JPanel after draw

扶醉桌前 提交于 2019-11-30 07:39:10
问题 I'm newbie in jave, my first project is draw, and save a image from JPanel, my draw is done, but I cant save it after I draw in JPanel :(, So can you help me to fix it when I open the image after draw, It doesn't contain anything :( here my codes: package image; import java.awt.BorderLayout; import java.awt.Button; import java.awt.Color; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Graphics; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import

How can I display a BufferedImage in a JFrame?

拜拜、爱过 提交于 2019-11-30 07:24:48
问题 I want to display variations of the same image in the same JFrame, for example display an image in JFrame, then replace it with gray scale of the same image. 回答1: You will have to repaint the JFrame whenever you update the image. Here is what a simple google on the topic brings up: (I use those tutorials for all my Java coding) Java Tutorial: Drawing an Image 回答2: To build on camickr's solution (for the lazy like me who want quick code to copy/paste) here's a code illustration: JFrame frame =

Convert Data-URL to BufferedImage

爱⌒轻易说出口 提交于 2019-11-30 06:49:16
I have a Data-URL from an image file and have to pass it through to another function. Along this path from Data-URL to the BufferedImage it needs to be a byteArray. my approach was the following: String dataUrl; byte[] imageData = dataUrl.getBytes(); // pass the byteArray along the path // create BufferedImage from byteArray BufferedImage inputImage = ImageIO.read(new ByteArrayInputStream(imageData)); // If the picture is null, then throw an unsupported image exception. if (inputImage == null) { throw new UnknownImageFormatException(); } The problem is, it always throws the

Can I have image alpha fade from left to right in java?

試著忘記壹切 提交于 2019-11-30 05:58:20
问题 I am making a game and want to have a single image 'fade' from left to right with the left part of the image having an alpha of 1.0 and the right having an alpha of 0.0. (note: I do not want it to be changing what it looks like over time, like fading in or out, but just fading from left to right and staying constant). An attempt to draw what I want the end result to look like is below: lll lll ll ll l l l l l lll lll ll ll l l l l l lll lll ll ll l l l l l lll lll ll ll l l l l l lll lll ll

Proper way of printing a BufferedImage in Java

隐身守侯 提交于 2019-11-30 05:32:47
I would like to know if there is a proper way of printing a BufferedImage in Java. Basically I have created a photo manipulation program which works fine, I can save images etc. But my real goal is to send it to the printer software so that you can select the amount of pages you want to print and page type. So my shortened question is, how do I send a buffered image to the printer so that a printer selection screen will popup etc and then be able to print? If anyone can show me an example of this, it would be greatly appreciated. Gilbert Le Blanc Here's one from one of my Java projects. This

Getting a BufferedImage as a resource so it will work in JAR file

99封情书 提交于 2019-11-30 05:16:09
问题 I'm trying to load an image into my java application as a BufferedImage, with the intent of having it work in a JAR file. I tried using ImageIO.read(new File("images/grass.png")); which worked in the IDE, but not in the JAR. I've also tried (BufferedImage) new ImageIcon(getClass().getResource( "/images/grass.png")).getImage(); which won't even work in the IDE because of a NullPointerException. I tried doing it with ../images, /images, and images in the path. None of those work. Am I missing

Java TGA loader

末鹿安然 提交于 2019-11-30 04:14:23
问题 I am looking for a small and free TGA image loading class or library for java. Ideally the result is a BufferedImage. Yes, I have already googled, but most results are outdated, or are quite big libraries that contain a lot of other stuff i dont need. I am looking for something small and simple that reads just TGA images. Thanks! 回答1: We use this class copied from some open source project to read TGA files. It's really old. It can only handle Targa files with most basic encoding. Give it a