Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: How do I draw an image, knowing the co-ordinates and rgb values??

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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.

  3. #3
    Member
    Join Date
    Jun 2011
    Location
    Rhode Island
    Posts
    69
    My Mood
    Bored
    Thanks
    11
    Thanked 7 Times in 6 Posts

    Default Re: How do I draw an image, knowing the co-ordinates and rgb values??

    Quote Originally Posted by byrtis View Post
    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
        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.

     
    // ... 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

  4. #4
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default 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.

     if (*&^^%%$$ > 35) {
     
                if (#$$%%^&&& > 0) {


    byrtis,

    Check out my image processing tutorial. You should find some of the snippets useful.

Similar Threads

  1. Draw part of an image
    By DSquire36 in forum AWT / Java Swing
    Replies: 5
    Last Post: June 2nd, 2011, 07:51 PM
  2. Retreiving the RGB values from an image
    By newparticipant in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 30th, 2011, 08:44 AM
  3. Return the rgb values from a jpg image
    By newparticipant in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 25th, 2011, 03:47 PM
  4. Replies: 2
    Last Post: February 14th, 2011, 05:36 PM
  5. Change the random draw line here for a mouseListener draw
    By Panda23 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 10th, 2011, 03:29 AM