Results 1 to 3 of 3
  1. #1
    Join Date
    May 2012
    Posts
    1
    Rep Power
    0

    Default Having issues with drawing portion of an image

    I am having issues with trying to draw a section of an image with my Frame, it is able to draw the whole image but when I try to do a section I see nothing being drawn on the screen.

    Java Code:
    package TestConsole;
    
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    
    import javax.imageio.ImageIO;
    
    public class AwtImage extends Frame {
        
        Image img;
        BufferedImage characters;
    
        public static void main(String[] args) throws IOException {
            AwtImage ai = new AwtImage();
        }
    
        public AwtImage() throws IOException {
            super("Image Frame");
            MediaTracker mt = new MediaTracker(this);
            img = ImageIO.read(this.getClass().getResource("RPConsole.png"));
            characters = ImageIO.read(this.getClass().getResource("RPChars.png"));
            mt.addImage(img, 0);
            //mt.addImage(characters, 1);
            setSize(356, 258);
            setVisible(true);
            setResizable(false);
            addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent we) {
                    dispose();
                }
            });
        }
    
        public void update(Graphics g) {
            paint(g);
        }
    
        public void paint(Graphics g) {
            if (img != null) {
                g.drawImage(img, 3, 25, this);
                g.drawImage(characters, 15, 15, 19, 19, 15, 15, 19, 19, this);
            } else
                g.clearRect(0, 0, getSize().width, getSize().height);
        }
    }
    RPConsole.png
    RPChars.png

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Moderator
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    9,918
    Rep Power
    16

    Default Re: Having issues with drawing portion of an image

    How big a part of that second image (in pixels X pixels) do you think you're drawing, and where?

    Do you have a reason for using the archaic AWT and not Swing, which supplanted it more than 10 years ago?

    db
    Why do they call it rush hour when nothing moves? - Robin Williams

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Moderator
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    9,918
    Rep Power
    16

    Default Re: Having issues with drawing portion of an image

    Moved from New to Java

    db
    Why do they call it rush hour when nothing moves? - Robin Williams

Similar Threads

  1. Having issues drawing Shapes into Jpanel
    By Greedychris in forum AWT / Swing
    Replies: 2
    Last Post: 03-06-2012, 05:32 AM
  2. Image issues
    By Toll in forum Advanced Java
    Replies: 7
    Last Post: 05-20-2011, 04:38 AM
  3. Printing portion of an image
    By thayalan in forum AWT / Swing
    Replies: 0
    Last Post: 07-06-2009, 02:04 AM
  4. Replies: 1
    Last Post: 04-17-2009, 12:44 AM
  5. drawing an image to an offscreen image
    By hunterbdb in forum Java 2D
    Replies: 9
    Last Post: 10-30-2008, 06:17 PM

Posting Permissions

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