How do I draw an image, knowing the co-ordinates and rgb values??
Ok....I have an array called FINALE[w*h+1][7]
In finale[][2], i have the red value
In finale[][3], i have the green value
In finale[][4], i have the blue value
In finale[][0], i have the x co-ordinate value
In finale[][1], i have the y co-ordinate value
With these values...I want to create ie draw an image of dimensions w*h...
How do I do that?
Could someone post a snippet of code for the same or tell me the steps please??
Hey thanks a lot....this forum seems to be a saviour!
Re: How do I draw an image, knowing the co-ordinates and rgb values??
Have you looked at the PixelGrabber class? Its get and set methods might do what you want.
Re: How do I draw an image, knowing the co-ordinates and rgb values??
Quote:
Originally Posted by
byrtis
With these values...I want to create ie draw an image of dimensions w*h...
How do I do that?
Could someone post a snippet of code for the same or tell me the steps please??
I am going to give you some ideas then show you the way I created a image on a canvas, just note that not all the code is in this snippet.
my code to draw a triangle
Code java:
public void paint(Graphics graphic) {
g = (Graphics2D) graphic;
//set the center and radius of the panel
reSize(getWidth(), getHeight());
// System.out.println("in paint");
// draw a square box
g.fillRect(getWidth() - (getWidth() - 20), getHeight() - 30, getWidth() - (getWidth() - 35),
getHeight());
// draw a square box on top of the box previously drawn
// g.fillRect(28, getHeight() - currentHeight, 20, getHeight());
g.fillRect(getWidth() - (getWidth() - 28), getHeight() - currentHeight, getWidth() - (getWidth() - 20),
getHeight());
// draws a ********** line
g.drawLine(28, getHeight() - currentHeight, getWidth(),
getHeight() - currentHeight);
calculateMag();
if (*&^^%%$$ > 35) {
if (#$$%%^&&& > 0) {
g.setColor(Color.green);
} else {
g.setColor(Color.red);
}
//rotates the images on the panel from this point on
this.g.translate(0, 0);
// System.out.println("elevation " + elevation);
// //rotating the panel to a degree in %%%%%%%%
g.rotate(Math.toRadians(90 - @@@@@), vp.getCenter().x, getHeight() - currentHeight);
// g.rotate(Math.toRadians(******), center.x, center.y);
//
// if (*&^^%%$$ > 0) {
// g.setColor(Color.GREEN);
// } else {
// g.setColor(Color.red);
// }
vp.setViewAngle(*&^^%%$$);
// //I add the triangle to the rotated jpanel
g.fillPolygon(vp.getTrianglePolygon());
//draws my @@@@@ line
g.setColor(Color.BLUE);
//draw a line for @@@@@ this will help later with ****** in the view area
g.drawLine(vp.getCenter().x, vp.getCenter().y, vp.getCenter().x,
Math.round(vp.getCenter().y - radius));
// graphic.setColor(Color.black);
// graphic.drawLine(this.getCenter().x, this.getCenter().y, this.getCenter().x,
// Math.round(this.getCenter().y - this.getRadius()));
additionally called a get method in different class to get the triangle this class keeps the running calculation and the Polygon when it called from the running program
this is vp class from the code above.
Code java:
// ... more code above...
private void setScopeView() {
this.left = new Point((int) (center.x - radius * Math.sin(Math.toRadians(-this.beta[arrayPosition ]))),
(int) (center.y - this.radius * Math.cos(Math.toRadians(-this.beta[arrayPosition]))));
this.right = new Point((int) (center.x - this.radius * Math.sin(Math.toRadians(
this.beta[arrayPosition]))), (int) (center.y - this.radius * Math.cos(Math.toRadians(
this.beta[arrayPosition]))));
//add points to polygon
if (this.p == null) {//check for null values
this.p = new Polygon();
} else {
this.p.reset();
}
//sets the points to create a polygon (triangle)
this.p.addPoint(center.x, center.y);
this.p.addPoint(left.x, left.y);
this.p.addPoint(right.x, right.y);
this.p.addPoint(center.x, center.y);
}
/**
* this will return the polygon that was created from setScopeView points
*
* @return trianglepolygon(4 point)
*/
public Polygon getTrianglePolygon() {
return this.p;
}
creating and drawing an image using buffers
drawImage
drawing buffered image on canvas
hope this helps
Re: How do I draw an image, knowing the co-ordinates and rgb values??
william,
Could you please explain this to me. I've never seen anything like it.
Code Java:
if (*&^^%%$$ > 35) {
if (#$$%%^&&& > 0) {
byrtis,
Check out my image processing tutorial. You should find some of the snippets useful.