Results 1 to 5 of 5
- 01-08-2012, 05:09 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 4
- Rep Power
- 0
extracting color from an image in java
i'm working on this java code to extract red,green and blue colors from an image.
Java Code:public class Mainclass { public static void main(String args[]) throws IOException { File e = new File( "image.jpg" ); BufferedImage bi= ImageIO.read(e); int w = bi.getWidth(); int h = bi.getHeight(); for (int x=0; x <= w; x++){ for (int y = 0; y <= h; y++){ int pixelCol=bi.getRGB(x,y); int r= (pixelCol>>16) & 0xff; int b = pixelCol & 0xff; int g = (pixelCol>>8) & 0xff; System.out.println(r,b,g); }}
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException:Coordinat e out of bounds!
at sun.awt.image.ByteInterleavedRaster.getDataElement s<ByteInterleavedRastere.java:301>
at java.awt.image.bufferedImage.getRGB<BufferedImage. java:870>
at Mainclass.main<Mainclass.java:27>
-
Re: extracting color from an image in java
upper bounds of Java arrays are 1 minus the length since arrays go from 0 to length - 1. So when you use a for loop that goes from 0 to <= w, you'll go out of bounds. Try going from 0 to < w, and same for y.
Also, please improve your code formatting because your code is difficult to read.
Oh, and welcome to the java-forums!
- 01-09-2012, 08:39 AM #3
Member
- Join Date
- Jan 2012
- Posts
- 4
- Rep Power
- 0
Re: extracting color from an image in java
yea sure thanks a lot!!!
- 09-18-2012, 02:18 PM #4
Member
- Join Date
- Sep 2012
- Posts
- 1
- Rep Power
- 0
Re: extracting color from an image in java
please anybody guide me in my final year project that is "extract text from image".
-
Re: extracting color from an image in java
Similar Threads
-
[HELP] How to locate a pixel in an image by color?
By santafan in forum Java 2DReplies: 4Last Post: 11-08-2011, 05:04 AM -
Problem in extracting the image in netbeans
By Esther in forum NetBeansReplies: 4Last Post: 09-05-2011, 11:16 AM -
Changing Image color
By Frecow in forum Java 2DReplies: 0Last Post: 04-04-2011, 10:16 AM -
Extracting Text from Image
By kish27 in forum Advanced JavaReplies: 3Last Post: 03-08-2011, 03:42 AM -
SWT color creating and image using.
By caryr in forum SWT / JFaceReplies: 2Last Post: 12-21-2009, 05:49 PM
Bookmarks