Results 1 to 3 of 3
  1. #1
    vagras is offline Member
    Join Date
    Dec 2011
    Posts
    1
    Rep Power
    0

    Default How to draw over a jpg image

    Hello,

    I need some help...I have a background picture representing a topology and I would like to write a piece of code allowing me to draw over it some angles, circles and some vectors. Which java packet is the most appropriate for this application. If there is any tutorial or any example code for this, please send me the link. Thank you for your help.

  2. #2
    jammas615 is offline Senior Member
    Join Date
    Jul 2011
    Location
    Melbourne, Victoria, Australia
    Posts
    155
    Rep Power
    3

    Default Re: How to draw over a jpg image

    If you want to draw over an image, draw the bottom layer before everything else

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    6

    Default Re: How to draw over a jpg image

    The various items in Java2D should help you out.

    If it were me, I would start with a JFrame (the window), and then subclass JPanel (this is where you'll draw).

    In the JPanel, override the paintComponent(Graphics g) method. Make sure you call super.paintComponent(g) as your first line in the paintComponent() method.

    Load the image with ImageIO (which will give you a BufferedImage). You can draw this first with g.drawImage(). Now, you can use the graphics object g to draw whatever else you need to. Take a look at the api on Graphics to see what else you can do (set colors, draw lines, text, shapes, etc...).

    When you're ready to get a little more advanced, you can work with Graphics2D which allows things like antialiasing, transformations, sub-pixel positioning, etc...

    Also, make sure you add your JPanel subclass to the JFrame, and if you plan on updating the info on the screen, make sure to call yourJframe.repaint().

    There are java2d tutorials all over the net, just google it, but the method I described above is simple and typical.

Similar Threads

  1. Replies: 1
    Last Post: 07-28-2011, 08:48 AM
  2. Help : reading image and draw it on GUI
    By Rodrigo91 in forum Java 2D
    Replies: 0
    Last Post: 03-26-2011, 10:01 PM
  3. Load and Draw image
    By TheSheepeh in forum New To Java
    Replies: 2
    Last Post: 03-19-2011, 12:19 PM
  4. Why doesn't the image draw?
    By MrFish in forum Java 2D
    Replies: 20
    Last Post: 11-16-2010, 07:32 PM
  5. how to draw an image inside of jscrollpane
    By paty in forum Java Applets
    Replies: 1
    Last Post: 07-24-2007, 12:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •