Solved

creating a Graphics object + setting pixel values

Posted on 2004-10-02
3
293 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 86
firstswap challenge 20 68
maven project error 5 48
Apps blocked by Java 9 64
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This video teaches viewers about errors in exception handling.

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now