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
Solved

creating a Graphics object + setting pixel values

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why my table column Id is not passed to java object? 4 44
Running JavaFX on JDeveloper 12C 1 54
SequenceInputStream example 3 19
Html Table Looping (part 2) 5 27
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…
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 “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…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

856 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