Solved

creating a Graphics object + setting pixel values

Posted on 2004-10-02
3
282 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:mayankeagle
mayankeagle 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

708 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

12 Experts available now in Live!

Get 1:1 Help Now