FAQ Database Discussion Community


2D BufferedImage colors stored in 1D array?

java,arrays,multidimensional-array,bufferedimage
The setRGB(int, int, int, int, int[], int, int) method in BufferedImage uses a 1D array to represent a 2D object (the image's colors). How does this work? How can I access such an array (the 1D one) using x/y coordinates?

How to convert a Type_Byte_Binary BufferedImage with Alpha to an TYPE_4BYTE_ABGR

java,image,bufferedimage
Im using the code BufferedImage imgIn = ImageIO.read(is); BufferedImage image; if (imgIn.getType() != BufferedImage.TYPE_BYTE_INDEXED) { image = new BufferedImage(imgIn.getWidth(), imgIn.getHeight(), BufferedImage.TYPE_4BYTE_ABGR); ColorConvertOp cco = new ColorConvertOp(imgIn.getColorModel() .getColorSpace(), image.getColorModel().getColorSpace(), null); cco.filter(imgIn, image); } else { image = imgIn; } When I'm pulling in an image with a Bit Depth of 4...

Is java.awt.GraphicsConfiguration thread-safe? What are the alternatives

java,thread-safety,awt,bufferedimage,swingworker
I'm extending javax.swing.JComponent to display a variable number of tiles, which all have the same size. If a tile needs a new appearance, a SwingWorker's doInBackground() renders a new BufferedImage for it. In done(), the image is stored and JComponent.repaint() is called, indicating the updated area and an intended delay....

Java BufferedImage / JPanel not updating new black pixel rows using JButton

java,swing,jpanel,bufferedimage,paintcomponent
Basically I have a (width x height) size of pixels in a buffered image and would like to draw simple horizontal BLACK lines, one after another into the Buffered Image / JPanel. Each click of the button should create a new horizontal line. Although the button event reaches the updateImage()...

Dynamically resize a bufferedimage in java

java,bufferedimage,image-resizing,affinetransform,imgscalr
I tried resizing the buffered image using AffineTransform as well as Scalr.resize Here are my codes for both of them. using Scalr.resize: BufferedImage buff = robot.createScreenCapture(new Rectangle(bufx,bufy,bufwidth,bufheight)); // x-coord, y-coord, width, height BufferedImage scrCapt = Scalr.resize(buff, Method.BALANCED, scrwidth, scrheight); using AffineTransform: BufferedImage buff = robot.createScreenCapture(new Rectangle(bufx,bufy,bufwidth,bufheight)); // x-coord, y-coord, width,...

Java IIOException caused by ZipException while trying to convert from String to PNG

java,servlets,png,bufferedimage,javax.imageio
My Java Servlet has a String coming from a client (all I know is that he is actually sending me a PNG as a parameter in a request with contentType = application/x-www-form-urlencoded), and I'm trying to convert it back to a File and save it. Here is my code (based...

Skew Buffered Image java

java,image-processing,bufferedimage
I have an image that I want to crop given the corners. For example I want to cut just the sudoku puzzle. I have the corners (x1, y1), (x2, y2), (x3, y3), (x4, y4). Tried this: javaxt.io.Image image = new javaxt.io.Image(bufferedImage); image.setCorners((float) pointTopLeft.getX(), (float) pointTopLeft.getY(), //UL (float) pointTopRight.getX(), (float) pointTopRight.getY(),...

Convert raw pixel data (as byte array) to BufferedImage

java,bytearray,bufferedimage,imagefilter
I have a requirement to use a native library which reads some proprietary image file formats (something about not reinventing our own wheel). The library works fine, it's just sometimes the images can get pretty big (the record I've seen being 13k x 15k pixels). The problem is my poor...

which image type is equivalent to 5

java,bufferedimage
I wrote the below code to check if the type of the image "RGB,BGR or any other type". when i ran the code i received value equals to 5, and i also checked the docs here but still i do not know which type is equivalent to number 5! please...

Writing a BufferedImage cache and save it to disk

java,caching,serialization,bufferedimage
I'm developing a java application in which I load some long lists containing images (downloaded from web), so I added a quick HashMap<String,BufferedImage> as a cache, to avoid redownloading the same image multiple times. This works fine and the application is way faster, but it would be nice to let...

Retrieving pixel data from Java Image

java,image,bufferedimage,scaling
Recently I have been attempting to scale pixel arrays (int[]) in Java. I used .setRGB() to add all my pixel data into the BufferedImage. BufferedImage then offers a function called .getScaledInstance(). This should work great for my purposes, but I ran into a problem. .getScaledInstance() returns a Image, not a...

Clip a BufferedImage to an Area

java,image,bufferedimage,clip
I'm trying to draw an image within a certain area. Right now I have code that fills an area with a RadialGradientPaint. Area lightArea = ... // fill the polygon with the gradient paint g.setPaint(light.paint); g.fill(lightArea); I would like to draw a BufferedImage in that area instead of drawing a...

Last image on JLabel is shown for all after adding JLayeredPane in loop

java,swing,bufferedimage
Sorry for the bad title, could not think of anything better. I am building a card game. The below method takes a Card object as argument and returns me a JLayeredPane with a JLabel having the image for the card. private JLayeredPane getCardPane(Card card) { JLayeredPane cardPane = new JLayeredPane();...

How can i delete previous BufferedImages from Graphics stack in Java?

java,bufferedimage
My problem is quite simple to understand. I have a JPanel inside a JFrame in order to display some graphics using the drawFormula() method below to display 3d points in screen using perspective projection. Everytime drawFormula() reaches its end I just recall itself to draw the shape again and again...

How can I modify the map of a Java IndexColorModel?

java,bufferedimage
I want to change one single color (yellow, to be somewhat specific) to another color in a BufferedImage which was loaded from a .GIF file. I should be able to do it easily enough with getRGB and setRGB, but it would much more efficient if I could just change the...

Can't get my panel to save as an image

java,swing,jframe,jpanel,bufferedimage
I made a simple paint program but there seem to be some problems. First off, when I run the program, the components don't show up until I drag my mouse over every single one. Secondly, the drawPanel image I create only saves the background of the panel and not the...

Rotating an Image object

java,image,graphics,rotation,bufferedimage
I have a method getImage() that needs to rotate an Image, store it in a new variable, then return that new Image. Here is my attempt, the image appears to be empty or something. It just does not show up on the screen: public Image getImage() { buffImage.createGraphics().rotate(direction); return buffImage;...

How to use compatibleImage to make drawing images faster in java2D?

bufferedimage,java-2d,drawimage
I'm writing a game in Java2D, and it runs smoothly on my computer and another computer I tested it on. However on another computer, with decent specs and same java settings, it is extremely slow. I'm pretty sure that I narrowed it down to the g.drawImage() command. After doing some...

Why does my find image in image function match non-exact matches?

java,image,computer-vision,bufferedimage
I am trying to implement various ways of finding image within image. I started with strict match. Let us have image for the image we are searching for and bigImage for the image we are searching in. /** Finds image in bigImage by exact pixel match (all pixels must be...

multiple instances of a class, loading images, make more efficient in java

java,bufferedimage,javax.imageio
I am making a game that has 100 bees chase you and they have sprites. When they hit you, you lose a life. If you get hit by all 100, you die and the game resets. The problem is that when it resets, it reloads the images for each bee....

how to write a file to a particular folder in java?

java,file,directory,bufferedimage
I did this program which takes screenshots using the robot class and bufferedimage class. The .png file which contains the screenshots is getting saved to the folder where the .java file is present.I want the image files to be written in another folder called screenshot which i created. I tried...

Splitting an Image Object into a 2D Array in Java

java,image,jlabel,multidimensional-array,bufferedimage
The aim of this little project is to break down an image (in this case a flag) into pieces like a jigsaw and store each piece in part of a 2D array. I then want to be able to view each piece individually so that I know it has worked....

image rotation method leaves something in the ram

java,memory,bufferedimage,affinetransform
I am currently working on a game and for more diversity of graphics I want to call a rotate(BufferedImage imgOld, int deg) method a few hundred times to rotate some graphics (eg. tree stumps). With unrotated graphics I never had any issues with memory. But as soon as I started...

Java colour collision detection

java,bufferedimage
I am making a 2d platformer game that takes in several premade images of "levels" and randomly inserts them into a list. The game never ends so it just keeps adding more images as needed. I am having a problem with the character moving between the images because when the...

Why is my gif image sent from servlet not animating?

java,image,gif,bufferedimage,javax.imageio
I have this following code in my servlet response.setContentType("image/gif"); String filepath = "PATH//TO//GIF.gif"; OutputStream out = response.getOutputStream(); File f = new File(filepath); BufferedImage bi = ImageIO.read(f); ImageIO.write(bi, "gif", out); out.close(); This code is just returning first frame of the image. How to achieve returning full GIF image ?...

Why does my Image not rotate?

java,rotation,applet,bufferedimage,graphics2d
This code displays the logo, but there's no rotation. Am I missing something? I've been trying to rotate for a long time. Everything displays fine, and the calculations are correct, but the image displays as a normal image import javax.swing.JApplet; import java.awt.Graphics2D; import java.awt.Graphics; import java.applet.Applet; import java.awt.Font; import java.awt.image.*;...

How to swap pixels of an image randomly?

java,arrays,image-processing,bufferedimage
I've been working on a Java program that reads an image, subdivides it into a definable number of rectangular tiles, then swaps the pixels of each tile with those of another tile, and then puts them back together and renders the image. An explanation of the idea: http://i.imgur.com/OPefpjf.png I've been...

How do I continue to paint on an image after redrawing it?

java,swing,jpanel,bufferedimage,paintcomponent
My program is meant to let a user paint on a bufferedimage and open/save files to paint on. After I open the bufferedimage I saved, I cannot continue to paint on it. Below is my code. Any other suggestions for moving around code or making it simpler would be appreciated....

Convert byte array of data type TYPE_4BYTE_ABGR to BufferedImage

java,bufferedimage
I have a byte array with type TYPE_4BYTE_ABGR, and I know its width and height, I want to change it to BufferedImage, any ideas?

How can I fetch image format from a URL in Java?

java,image,image-processing,bufferedimage,javax.imageio
I have an image that I fetch from a url that has no extension(jpg, gif,png, etc). I have no problem downloading the image. BufferedImage image = null; URL url = new URL(link); image = ImageIO.read(url); However, I wanted to know the extension of the file before saving to disk. I...

Easily print image on the screen for debug purposes in a blocking manner

java,debugging,bufferedimage
I am working on a computer vision project and somewhere in a process an endless loop happens. It seems that my image data is being corrupted. In past, I used to save debug results on the disk using this method: public static boolean saveToPath(String path, BufferedImage image) { File img...

How do I test a pixel of a bufferedimage for a certain color in Java

java,image,pixel,bufferedimage
I'm trying to take a screenshot and then look through it for a pixel that has a certain color. Firstly, I tried to just print the color of an image at a certain xy coordinate but I could not even do that. What am I doing wrong? static int ScreenWidth;...

BufferedImage to InputStream - Format is different

java,inputstream,bufferedimage,javax.imageio
I am trying to convert my BufferedImage to an Inputstream using the following: BufferedImage bi = ImageIO.read(file.getInputStream()); bi = Scalr.resize(bi, 300); ByteArrayOutputStream os = new ByteArrayOutputStream(); ImageIO.write(bi, file.getContentType(), os); //the content type is specified as image/jpeg The problem I am facing is that my file.getContentType() returns the value as "image/jpeg"...

How to create custom high-def images in Java

java,bufferedimage,graphics2d
I am creating images in Java that have fonts written on them with a transparent background. I make the fonts different colors and also different types of font styles so I need the program to be dynamic. The issue is that I am using Graphics2D and writing on a Buffered...

Writing Jpanel to Buffered Image stack overflow

java,swing,bufferedimage
I'm trying to write a JPanel Picture to a BufferedImage (later converted to Rendered Image). I am getting a stack overflow error in the AWT-EventQueue-0 thread for some reason and am not sure if there is a reason I have overlooked. The code in question: public BufferedImage createImage() { int...

Java draw component on java.awtGraphics

java,swing,bufferedimage
I have a method that creates a buffered image and I want to be able to create a progress bar and then paint that onto the buffered image. Any idea how I can achieve this please? public void paint() { BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB); Graphics g =...

How do I save a BufferedImage to a pgm file?

java,save,bufferedimage,jai,pgm
I looked through the internet but I could not find an answer. I have a pgm file which I use as a BufferedImage to do a convolution (I use JAI for that) but I am having trouble in saving it back to a pgm file. So far I used following...

Resize image without loss of information

java,image,resize,scale,bufferedimage
I was trying to do really the same functionality of resizing images like in MS Word. I want to resize BufferedImage but I’m losing some information during process of resizing. I tried to implement two approaches, but both produced same result. Before any resizing: Picture after few resize actions in...

Cannot instantiate the type ColorModel

java,awt,bufferedimage
Please don't dislike this "generic question", since it really is a problem. I also searched other questions and the problem there was always that the people wanted to instantiate interfaces. That's not my case. The class ColorModel is not an interface and has a constructor that takes an int. Why...

Get average color on bufferedimage and bufferedimage portion as fast as possible

java,computer-vision,bufferedimage
I am trying to find image in an image. I do this for desktop automation. At this moment, I'm trying to be fast, not precise. As such, I have decided to match similar image solely based on the same average color. If I pick several icons on my desktop, for...

I am making a multithreaded application to process an image yet the sequential version is faster, why?

java,multithreading,bufferedimage
I am having static BufferedImage in the threads and letting each thread modify some sections of the image. The processing is extremely independent as each pixel is done separately, yet the sequential version is faster how could I fix that? edit 1: here how the code looks like public static...

Read in Bufferedimage pixel values then manipulate each one and write to file

java,rgb,bufferedimage,pixels,bitmapimage
I am currently trying to read in an image pixel by pixel and change each colored pixel to the rgb value of (100,100,100). For whatever reason when I check the values of each pixel one the image is saved it has all the colored pixels as (46,46,46) instead. Here is...