Solved

creating a Graphics object + setting pixel values

Posted on 2004-10-02
3
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: 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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

739 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