Solved

creating a Graphics object + setting pixel values

Posted on 2004-10-02
3
311 Views
Last Modified: 2010-03-31
Hi !!

what i'm trying to do is .. create a Graphics object of dimensions , say, 500 x 500 pixels.

Then, given some x and y coordinates, call the function drawPolygon a number of times to draw a few polygons in the graphics object.

And finally, retrieve the pixel value for each coordinate
e.g. (pseudocode),
-----------------
for i=0 to 499 ;
---for j=0 to 499;
------int thecolor = graphicsobject.getpixelvalue(i,j)
-----------------

is it possible to do something like this ??

thanks :)
muska202
0
Comment
Question by:muskad202
3 Comments
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 20 total points
ID: 12206495
If you wanna draw polygons, etc, then why not use the drawPolygon (), drawRect (), etc methods of the Graphics2D class?

http://www.javaalmanac.com/egs/java.awt/DrawBasic.html
0
 
LVL 2

Author Comment

by:muskad202
ID: 12206540
ok .. i'll try that ..
is there any way to get the color value of a particular pixel (row,col) from a Graphics2D object ?

thanks :)
muskad202
0
 
LVL 92

Accepted Solution

by:
objects earned 30 total points
ID: 12209325
if you are only insterested in the pixel color then paint your polyfon to a BufferedImage, and use it's getRBG() method to retrieve the pixel value

BufferedImage bi = ...
Graphics g = bi.getGraphics();

// do your painting

for i=0 to 499 ;
---for j=0 to 499;
------int thecolor = bi.getRGB(i,j)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet example 11 55
maven module vs maven project 3 69
How do I remove an object from a 3 51
Print Rhino Java Array in Javascript 1 30
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question