Solved

# Pixel Information of a Image using Link List

Posted on 2005-04-11
200 Views
If some one could provide me with a code which extracts the pixel information of an image of any type (Information refers to the RGB Color and the width & Height of the image).  The information of the image should be stored in a Link List.

Regards
0
Question by:ZUBAIR

LVL 37

Expert Comment

0

LVL 86

Expert Comment

0

LVL 30

Expert Comment

0

LVL 35

Expert Comment

>> The information of the image should be stored in a Link List.

Each pixel should be a node in a linked list?

I'm guessing this is a homework assignement, as that makes little or no sense otherwise ;-)
0

Author Comment

I am learning java and it is obvious that a beginner needs a push or a help from there friends.

Anyhow what i was trying to do was that i need to store information of each and every pixel in a Link list where every pixels properties are saved individually, values of red, green, blue and the axis on which the pixel is lying (X-1, Y-1).

If you need further clarification - please do comment
0

LVL 35

Expert Comment

Why don't you just use an array of int?

int w = img.getWidth() ;
int h = img.getHeight() ;
int[] pixels = new int[ w * h ] ;

then, you can get the current X, Y position by modding and dividing like so:

// loop  through every pixel
for( int i = 0 ; i < pixels.length ; i++ )
{
int x = i % w ;
int y = i / w ;
}

and you can get the red, green and blue pixel colours by shifting and bitwise ANDing:

public final static int getRed(int color) {
return (color & 0x00FF0000 ) >>> 16 ;
}

public final static int getGreen(int color) {
return (color & 0x0000FF00 ) >>> 8;
}

public final static int getBlue(int color) {
return ( color & 0x000000FF ) ;
}
0

LVL 35

Expert Comment

Storing it in a linked list would lead to using a lot of memory very quickly...
0

Author Comment

Thanks Tim,

The reason i am doing so is to learn about linklist. If you could guide me - i would be grateful
0

LVL 35

Expert Comment

is an example of writing your own linked list in java :-)

http://java.sun.com/j2se/1.4.2/docs/api/java/util/LinkedList.html is a java class which does it all for you (which I guess you don't want) :-)

Tim
0

LVL 35

Expert Comment

what specific difficulty do you have with your code?

I can't just write a Linked list for you...but I may be able to point out bugs in your existing code...

Tim
0

Author Comment

Thanks a lot Tim :)

I have understood the basic concept of link list - i am a bit confused that how to store 5 different informations in a single node. (Five Different Information are ; RGB Color + X & Y axis of the pixel)

Zubair
0

LVL 35

Accepted Solution

public class Node
{
Node next ; // the next node in the list
int someValue ;
String someString ;
double whatever ;
int anotherInt ;
}

etc..

it's a class...store whatever you want in it :-)

Tim
0

## Featured Post

### Suggested Solutions

1. Package the applet into a JAR file. The applet must be in a JAR file before a certificate can be attached to it. Use the jar JDK utility. If the applet was previously referenced with the help of a codebase attribute in  tag, replace the codebase …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.