Draw ontop of an image

Can anyone tell me how i can paint a rectangle ontop of an image.
I have this code where ive used mediatracker in another class called ImageCanvas that extends canvas. This is added to the screen below a panel that has another image and a button. When the button is clicked it draws a dice using paint from another class. But because i have an image already on the screen this will not paint the dice ontop of the image. If i do not have the image the paint will work.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Dicetoon extends Applet implements ActionListener{
     Button diceButton; // action button
     private Panel gamePanel;
     private Dice dice = new Dice();
     private int diceValue;
     public void init() {
          setLayout (new BorderLayout());
          gamePanel = new Panel();
               GridBagLayout layout = new GridBagLayout();
               GridBagConstraints constraints = new GridBagConstraints();
               gamePanel.setLayout(layout);
               gamePanel.setBackground(new Color(8,16,16));
               constraints.gridwidth = GridBagConstraints.REMAINDER;
               gamePanel.add(new ImageCanvas(getImage(getCodeBase(),"dictoonlogo.jpg")),constraints);
     // add button and listener to read list
               diceButton = new Button (" Enter ");
               gamePanel.add (diceButton);
               diceButton.addActionListener (this);
          //diceButton.setBounds(15,159,120,40);
               diceButton.setBackground(Color.black);
               diceButton.setForeground(Color.white);
          add("North",gamePanel);
          this.add(new ImageCanvas(getImage(getCodeBase(),"background.jpg")));
     public void actionPerformed (ActionEvent e) {
          rollDice();
//This is where a dice is drawn
     public void rollDice(int dicePosition) {
     dice.throwDice();
diceValue = dice.readValue();
DrawDice drawdice = new DrawDice();
     Graphics drawGraphics = getGraphics();
     drawdice.drawDice(drawGraphics, diceValue);
THe 2nd class that used for the image
public class ImageCanvas extends Canvas {
     private transient Image image;
     public ImageCanvas(Image theimage){
          image=theimage;
          if(image != null){
               MediaTracker mediatracker = new MediaTracker(this);
               try{
                    mediatracker.addImage(image, 0);
                    mediatracker.waitForAll();
               catch(InterruptedException interruptedexception){
               repaint();
public void paint(Graphics g) {
Dimension d = this.getSize();
g.drawImage(image, 0, 0, 300, 300, this);
some of the draw dice class
public class DrawDice extends Panel {
     public void drawDice(Graphics drawDice, int diceValue) {
          drawDice.setColor (Color.red);
          //drawDice.fillRect (250, 300, 50, 50);
          drawDice.fillRect (250, 300, 50, 50);
//switch staement.........

The dice are being drawn, then covered by the image. You are passing the graphics context of the applet panel to drawDice(), so the dice are painted directly on the applet panel. The problem is the background image occupies the same area in the applet container, so the applet panel fires a paint message to the image, which then repaints itself over the dice.
Why is DrawDice a Panel? You should probably make a panel to contain the background image/painted dice, and add this to the applet panel instead of adding the background image directly. This will give you a paint method that can draw the background image then paint the dice.
GuyD
Can anyone tell me how i can paint a rectangle ontop
of an image.
I have this code where ive used mediatracker in
another class called ImageCanvas that extends canvas.
This is added to the screen below a panel that has
another image and a button. When the button is
s clicked it draws a dice using paint from another
class. But because i have an image already on the
screen this will not paint the dice ontop of the
image. If i do not have the image the paint will
work.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Dicetoon extends Applet implements
ActionListener{
     Button diceButton; // action button
     private Panel gamePanel;
     private Dice dice = new Dice();
     private int diceValue;
     public void init() {
          setLayout (new BorderLayout());
          gamePanel = new Panel();
               GridBagLayout layout = new GridBagLayout();
GridBagConstraints constraints = new
new GridBagConstraints();
               gamePanel.setLayout(layout);
               gamePanel.setBackground(new Color(8,16,16));
constraints.gridwidth =
h = GridBagConstraints.REMAINDER;
gamePanel.add(new
new
ImageCanvas(getImage(getCodeBase(),"dictoonlogo.jpg")),
onstraints);
     // add button and listener to read list
               diceButton = new Button (" Enter ");
               gamePanel.add (diceButton);
               diceButton.addActionListener (this);
          //diceButton.setBounds(15,159,120,40);
               diceButton.setBackground(Color.black);
               diceButton.setForeground(Color.white);
          add("North",gamePanel);
this.add(new
ew
ImageCanvas(getImage(getCodeBase(),"background.jpg")));
     public void actionPerformed (ActionEvent e) {
          rollDice();
//This is where a dice is drawn
     public void rollDice(int dicePosition) {
     dice.throwDice();
diceValue = dice.readValue();
DrawDice drawdice = new DrawDice();
     Graphics drawGraphics = getGraphics();
     drawdice.drawDice(drawGraphics, diceValue);
THe 2nd class that used for the image
public class ImageCanvas extends Canvas {
     private transient Image image;
     public ImageCanvas(Image theimage){
          image=theimage;
          if(image != null){
MediaTracker mediatracker = new
ew MediaTracker(this);
               try{
                    mediatracker.addImage(image, 0);
                    mediatracker.waitForAll();
               catch(InterruptedException interruptedexception){
               repaint();
public void paint(Graphics g) {
Dimension d = this.getSize();
g.drawImage(image, 0, 0, 300, 300, this);
some of the draw dice class
public class DrawDice extends Panel {
public void drawDice(Graphics drawDice, int
diceValue) {
          drawDice.setColor (Color.red);
          //drawDice.fillRect (250, 300, 50, 50);
          drawDice.fillRect (250, 300, 50, 50);
//switch staement.........

Similar Messages

  • Saving Image Files on Disk after drawing lines on the Image

    Hi guys,
    I am presently working on a swing project in which I need to draw lines on a image and then store the modified image in .gif, .jpg or .bmp file format.
    I can't seem to find an documentation dealing with this situation.
    Any help will be highly appreciated
    Abhi

    Ive just been looking for the same. Theres an article (and a class) on javaworld on subject of saving bitmap-files, and in another thread in this forum, a guy described how to make jpg. with the jdk1.4 .... Like this:
    int w = comp.getWidth();
    int h = comp.getHeight();
    BufferedImage im = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = im.createGraphics();
    comp.paint(g2);
    g2.dispose();
    ImageIO.write(im, "jpeg", new File("foo.jpeg"));
    im.flush();
    Im just referring, havent tried it yet. Good luck.
    Stig.

  • Draw 20% of one image and 80% of another?

    Hi all,
    I'm creating a UI functionality whereby a user holds down a button and an image of a glass slowly fills up.
    The way I'm thinking of implementing this is to have two different images, one of the empty glass and one of the full glass. As the user holds down the button, the image of the first is slowly replaced by the image of the second. E.g., after one second, 20% of the full image is shown at the bottom, 80% of the first is shown at the top.
    The timing stuff I think I can do with a thread, so I'm not too worried about that. However, what I need is a simple method, or maybe a whole class, that can take two images and draw x% of one on the bottom and y% of the other on the top.
    Can anyone think of a simple way to implement this?
    Thanks,
    Tim

    Hmmm... after playing with that a while, it doesn't look like that will do the trick. As far as I can tell, the drawImage methods will always scale the image if you pass it in a rectangle of a different size. So trying to get 50% of a full glass on top of an empty glass results in a squished full glass.
    Instead I realized I could do it using Graphs.clipRect, like so:
    public class OverlayedImageIcon extends ImageIcon
         private Image overlayImage;
         private float overlayPercent;
         public OverlayedImageIcon(URL url)
             super(url);
         public void setOverlayImage(Image image){
              this.overlayImage = image;
              loadImage(overlayImage);
         public void setOverlayPercent(float percent){
              this.overlayPercent = percent;
         public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
              super.paintIcon(c, g, x, y);
              Shape oldClip = g.getClip();
              int subtractHeight = (int) ((float)getIconHeight() * overlayPercent);
              g.clipRect(0, getIconHeight() - subtractHeight, getIconWidth(), getIconHeight());
            g.drawImage(overlayImage, x, y, getIconWidth(), getIconHeight(), getImageObserver());
            g.setClip(oldClip);
    }Thanks for pointing me in the right direction, though!

  • Whats the easiest/simplest way to draw a board with images on it?

    Im doing a project for school and im familiar with gui�s but I never done any work on drawing a board (10 x 10) and being able to place a jpg in each box. I have an overall idea of what im thinking about doing. Which is of course using a multidimensional array, and drawing the board on a Jpanel. From my understanding, the gui is just for looks the real action is going on whenever the user clicks on a square and getting the x,y coordinates, and placing or getting that image�s name/number from the array based on the coordinates right? The only part im not so sure about is the drawing of the board and placing jpgs on it based on the users clicks. Any sugguestions to help me get started?

    hey db,
    thanks for your reply, out of curiousity will this
    slow down the process of displaying the pictures
    since i will be using MediaTracker(or is there a
    better way of displaying gif/jpg?)? My favorite way is to add a JLabel to the panel, create an ImageIcon from the jpg and then call setIcon on the Jlabel passing it the ImageIcon. ImageIcon uses its own MediaTracker so you don't need to mess with one.
    i was also hinted
    to do this from a friend which was to create 1 X by X
    pixel panel first then have a parent panel that
    contains 100 of them (10x10) but wasnt sure since i
    only knew 1 way of doing it which was getting the xy
    coordinates. since this project will allow the user
    to move pieces sorta like chess where each piece has
    the ability to move a certain # of spaces and based
    on their characteristics they can either win or get
    "kill", i wasnt sure as to which was the best way of
    doing this.
    btw you said when creating an ImagePanel i wouldnt
    have to calculate where the user clicked on, for
    example if the user clicks on the 2nd row 1st box
    (which is 0,1 in my array) will be the actual
    ImagePanel be returned so i can either remove the
    image and place it elsewhere without having to get
    the xy coordinates or do i have the concept wrong?My thought was that clicking on a particular panel would cause it to become the "active panel" which you could then manipulate as you wish.
    >
    thanks again db!The link camickr provided is also a good solution
    Cheers
    DB

  • Automatically have motion trace a line drawing over an imported image?

    I was wondering if there is any way for motion to automatically follow the path of a line of a drawing that I imported from photoshop so that I could make this image appear to draw on? It would seem sensible that the program have some way of selecting a particular color (the way you can do that in photoshop) and then create a line path out of that to replace the imported image so write on effects or anything else could then be applied. Anyone have thoughts on this?

    It'd be nice, but there currently isn't a way to turn a bitmap into a path... you can key a color, but that's about it...
    Patrick

  • Why rotated rectangle tool can't draw rotated ROI on image?

    I want to use the tool window to draw a rotated rectangle on image, but each time, it seems only draw a rectangle, it can't rotate. Don't know why?
    In Vision Assitant, if I use rotated rectangle tool, it will show like this:
    Using the cross lines in rectangle, I can rotate my ROI, it is OK.
    Run the sample code: C:\Users\Public\Documents\National Instruments\CVI\samples\Vision\2. Functions\Geometric Matching, change     imaqShowToolWindow (FALSE);
    to  imaqShowToolWindow (TRUE); 
    on line 93#. Compile then run. Seems I also can't rotate my ROI, don't know why?
    Please show me? Thank you. 

    Hi,
    You cannot perform action on an overlay. In order to achieve what you want to do, I suggest you to use the ROI property in an image property node. Then just pass your ROI coordinates, the ROI will be updated automatically whenever your coordinates changes. You can drag a ROI this is impossible with an overlay.
    Regards

  • Better to draw graphics or show image of previously drawn image?

    I have an AWT app that I have a fundamental question about best practices. I have a (double buffered) panel that has objects that move across it. As it is now, on each iteration, each of the objects is redrawn every time with the graphics object from the panel. For instance, is it better to do this (I am going to water this down heavily):
    class BlobImage{
         drawImage(Graphics g){
              g.drawABunchOfStuff
    class BlobImagePanel{
         private List<BlobImage> blobImages = new ArrayList<BlobImage>();
         public repaint{
              Graphics g = this.getGraphics;
              for (BlobImage bi: blobImages){
                   bi.drawImage(g);
         }Or is it better for the BlobImage to render a BufferedImage once, and then just give back that image each time like this:
    class BlobImage{
         private BufferedImage bufferedImage=null;
         public BlobImage(){
              if (bufferedImage==null){
                   bufferedImage = new BufferedImage(width, height, imageType);
                   Graphics g = bufferedImage.getGraphics();
                   this.drawImage(g);
         drawImage(Graphics g){
              g.drawABunchOfStuff;
         getImage(){
              return bufferedImage;
    class BlobImagePanel{
         private List<BlobImage> blobImages = new ArrayList<BlobImage>();
         public repaint{
              Graphics g = this.getGraphics;
              for (BlobImage bi: blobImages){
                   g.drawImage(bi.getImage,x,y,width,height,this);
    }Assuming the x and y positions change each time the panel is repainted, is it better to continually draw each object with the parameterized graphics object with the new positions, or is it better to just create the image, and then let the panel move the entire image around?
    Let me reiterate() that this is pseudocode, and probably not compilable. It's the concepts that I am asking about.
    Edited by: J_Y_C on Jan 10, 2008 2:04 PM

    Ah ha! ARGB, got it.
    What I ended up doing was something like this:
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();          
    GraphicsDevice gs = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gs.getDefaultConfiguration();
    redWordImage = gc.createCompatibleImage(this.dimensions.width, this.dimensions.height, Color.BITMASK);Would there be any reason I would be better off with one versus the other? Or am I just doing more typing to arrive at the same destination?

  • How to draw make the overlapped images on a JToggle Button draggable

    Hello all:
    I have a JPanel chart set with GridBagLayout. Each cell is a JButton,
    I've create several overlaping images (from my existing images) using JLayeredPane
    and adding on one particular cell JToggleButton. The images are displayed, but I don't know
    how to make it draggable for users to drag to another cell within GridbagLayout.
    I have been stuck on this for a long time, I'd appreciate if anyone give me some help
    on this.

    Hi kglad -
    Thanks. That worked perfectly.
    Surely you jest with me.  Since I couldn't script a play button where in my brain do you think I would I find the cells to "use listeners for the video playing/stopping to control bigPlay_btn's _visible property".
    That's okay.  I'm sure after answering almost 50,000 questions it's easy to forget who you're talking to.
    Thanks again.
    Josh

  • Photoshop has suddenly started placing a large black box ontop of the image - its only present on the monitor if I save the image it has gone - the box (some times black sometime white) obscures what Im doing

    This has suddenly started - a black box (some times white )
    appears over the top of the image & obscures what Im doing. Its not present when I save the file - only when Im trying to work on it. I cant see what Im doing to the image
    Help !!
    James

    Looks like a bug somewhere in PS - would be interesting to find out if it's happening to more than just us.
    Actually this looks a lot like a bug with a GPU driver.
    Has the issue reoccurred since you turned off GPU usage?
    My trouble is I just use PS and expect it to work.
    Well, as Adobe did not make your computer, OS, GPU, … you have to do your own trouble-shooting to verify if the issue is actually with an Adobe application or with another component.

  • How to use the Rectangle class to draw an image and center it in a JPanel

    I sent an earlier post on how to center an image in a JPanel using the Rectangle class. I was asked to send an executable code which will show the malfunction. The code below is an executable code and a small part of a very big project. To simplifiy things, it is just a JFrame and a JPanel with an open dialog. Once executed the JFrame and the FileDialog will open. You can then navigate to a .gif or a .jpg picture and open it. What I want is for the picture to be centered in the middle of the JPanel and not the upper left corner. It is also important to stress that, I am usinig the Rectangle class to draw the Image. The region of interest is where the rectangle is created. In the constructor of the CenterRect class, I initialize the Rectangle class. Then I use paintComponent in the CenterRect class to draw the Image. The other classes are just support classes. The MyImage class is an extended image class which also has a draw() method. Any assistance in getting the Rectangle to show at the center of the JPanel without affecting the size and shape of the image will be greatly appreciated.
    I have divided the code into three parts. They are all supposed to be on one file in order to execute.
    import java.awt.*;
    import java.awt.image.*;
    import javax.swing.*;
    public class CenterRect extends JPanel {
        public static Rectangle srcRect;
        Insets insets = null;
        Image image;
        MyImage imp;
        private double magnification;
        private int dstWidth, dstHeight;
        public CenterRect(MyImage imp){
            insets = getInsets();
            this.imp = imp;
            int width = imp.getWidth();
            int height = imp.getHeight();
            ImagePanel.init();
            srcRect = new Rectangle(0,0, width, height);
            srcRect.setLocation(0,0);
            setDrawingSize(width, height);
            magnification = 1.0;
        public void setDrawingSize(int width, int height) {
            dstWidth = width;
            dstHeight = height;
            setSize(dstWidth, dstHeight);
        public void paintComponent(Graphics g) {
            Image img = imp.getImage();
         try {
                if (img!=null)
                    g.drawImage(img,0,0, (int)(srcRect.width*magnification), (int)(srcRect.height*magnification),
              srcRect.x, srcRect.y, srcRect.x+srcRect.width, srcRect.y+srcRect.height, null);
            catch(OutOfMemoryError e) {e.printStackTrace();}
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Opener().openImage();
    class Opener{
        private String dir;
        private String name;
        private static String defaultDirectory;
        JFrame parent;
        public Opener() {
            initComponents();
         public void initComponents(){
            parent = new JFrame();
            parent.setContentPane(ImagePanel.panel);
            parent.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
            parent.setExtendedState(JFrame.MAXIMIZED_BOTH);
            parent.setVisible(true);
        public void openDialog(String title, String path){
            if (path==null || path.equals("")) {
                FileDialog fd = new FileDialog(parent, title);
                defaultDirectory = "dir.image";
                if (defaultDirectory!=null)
                    fd.setDirectory(defaultDirectory);
                fd.setVisible(true);
                name = fd.getFile();
                if (name!=null) {
                    dir = fd.getDirectory();
                    defaultDirectory = dir;
                fd.dispose();
                if (parent==null)
                    return;
            } else {
                int i = path.lastIndexOf('/');
                if (i==-1)
                    i = path.lastIndexOf('\\');
                if (i>0) {
                    dir = path.substring(0, i+1);
                    name = path.substring(i+1);
                } else {
                    dir = "";
                    name = path;
        public MyImage openImage(String directory, String name) {
            MyImage imp = openJpegOrGif(dir, name);
            return imp;
        public void openImage() {
            openDialog("Open...", "");
            String directory = dir;
            String name = this.name;
            if (name==null)
                return;
            MyImage imp = openImage(directory, name);
            if (imp!=null) imp.show();
        MyImage openJpegOrGif(String dir, String name) {
                MyImage imp = null;
                Image img = Toolkit.getDefaultToolkit().getImage(dir+name);
                if (img!=null) {
                    imp = new MyImage(name, img);
                    FileInfo fi = new FileInfo();
                    fi.fileFormat = fi.GIF_OR_JPG;
                    fi.fileName = name;
                    fi.directory = dir;
                    imp.setFileInfo(fi);
                return imp;
    }

    This is the second part. It is a continuation of the first part. They are all supposed to be on one file.
    class MyImage implements ImageObserver{
        private int imageUpdateY, imageUpdateW,width,height;
        private boolean imageLoaded;
        private static int currentID = -1;
        private int ID;
        private static Component comp;
        protected ImageProcessor ip;
        private String title;
        protected Image img;
        private static int xbase = -1;
        private static int ybase,xloc,yloc;
        private static int count = 0;
        private static final int XINC = 8;
        private static final int YINC = 12;
        private int originalScale = 1;
        private FileInfo fileInfo;
        ImagePanel win;
        /** Constructs an ImagePlus from an AWT Image. The first argument
         * will be used as the title of the window that displays the image. */
        public MyImage(String title, Image img) {
            this.title = title;
             ID = --currentID;
            if (img!=null)
                setImage(img);
        public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h) {
             imageUpdateY = y;
             imageUpdateW = w;
             imageLoaded = (flags & (ALLBITS|FRAMEBITS|ABORT)) != 0;
         return !imageLoaded;
        public int getWidth() {
             return width;
        public int getHeight() {
             return height;
        /** Replaces the ImageProcessor, if any, with the one specified.
         * Set 'title' to null to leave the image title unchanged. */
        public void setProcessor(String title, ImageProcessor ip) {
            if (title!=null) this.title = title;
            this.ip = ip;
            img = ip.createImage();
            boolean newSize = width!=ip.getWidth() || height!=ip.getHeight();
         width = ip.getWidth();
         height = ip.getHeight();
         if (win!=null && newSize) {
                win = new ImagePanel(this);
        public void draw(){
            CenterRect ic = null;
            win = new ImagePanel(this);
            if (win!=null){
                win.addIC(this);
                win.getCanvas().repaint();
                ic = win .getCanvas();
                win.panel.add(ic);
                int width = win.imp.getWidth();
                int height = win.imp.getHeight();
                Point ijLoc = new Point(10,32);
                if (xbase==-1) {
                    xbase = 5;
                    ybase = ijLoc.y;
                    xloc = xbase;
                    yloc = ybase;
                if ((xloc+width)>ijLoc.x && yloc<(ybase+20))
                    yloc = ybase+20;
                    int x = xloc;
                    int y = yloc;
                    xloc += XINC;
                    yloc += YINC;
                    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
                    count++;
                    if (count%6==0) {
                        xloc = xbase;
                        yloc = ybase;
                    int scale = 1;
                    while (xbase+XINC*4+width/scale>screen.width || ybase+YINC*4+height/scale>screen.height)
                        if (scale>1) {
                   originalScale = scale;
                   ic.setDrawingSize(width/scale, height/scale);
        /** Returns the current AWT image. */
        public Image getImage() {
            if (img==null && ip!=null)
                img = ip.createImage();
            return img;
        /** Replaces the AWT image, if any, with the one specified. */
        public void setImage(Image img) {
            waitForImage(img);
            this.img = img;
            JPanel panel = ImagePanel.panel;
            width = img.getWidth(panel);
            height = img.getHeight(panel);
            ip = null;
        /** Opens a window to display this image and clears the status bar. */
        public void show() {
            show("");
        /** Opens a window to display this image and displays
         * 'statusMessage' in the status bar. */
        public void show(String statusMessage) {
            if (img==null && ip!=null){
                img = ip.createImage();
            if ((img!=null) && (width>=0) && (height>=0)) {
                win = new ImagePanel(this);
                draw();
        private void waitForImage(Image img) {
        if (comp==null) {
            comp = ImagePanel.panel;
            if (comp==null)
                comp = new JPanel();
        imageLoaded = false;
        if (!comp.prepareImage(img, this)) {
            double progress;
            while (!imageLoaded) {
                if (imageUpdateW>1) {
                    progress = (double)imageUpdateY/imageUpdateW;
                    if (!(progress<1.0)) {
                        progress = 1.0 - (progress-1.0);
                        if (progress<0.0) progress = 0.9;
    public void setFileInfo(FileInfo fi) {
        fi.pixels = null;
        fileInfo = fi;
    }

  • How do I draw an image on a JPanel?

    To be honest I have no idea even where to start. I tried hacking through the tutorials but it just didn't help me (normally they do, I don't what's up).
    Anyway, so what I'm trying to do is build a game. The Graphics2D is great for simple shapes but drawing characters is getting kind of ridiculous (tedious + difficult + looks bad). So, I need to figure out how to display an image on a JPanel.
    To that end I have several questions.
    1 - What image type do I use? Like jpeg, bmp, gif, etc.
    2 - How do I make parts of it transparent?
    3 - How do I make it appear on the screen, given some coordinates on the JPanel?

    To draw an image directly to a JPanel given certain coordinates, you have to create a custom JPanel and override its paintComponent() method. Like this:
    class PaintPanel extends JPanel{
    public void paintComponent(Graphics g){
    super.paintComponent(g);
    //painting code goes here}
    }Java can load in and draw GIF and JPEG images. If you decide to use GIF files, any good image editor like Adobe Photoshop should be able to make them transparent for you before the fact. If you want to set transparency within your java program you will have to create a BufferedImage and make certain colors within it transparent, but I would like to know how to do that as much as you do.

  • Trouble drawing on saved images in whiteboard, please help!

    I use the Image.IO.write(image,"png",file) method to save my whiteboard drawings onto a file and it displays fine when I import it. But when I draw on it it seems some of my whiteboard buttons are "blending in" with the drawing area where the image is. I guess a way to imagine is there is a row of buttons then a panel containing the image. When I draw on the image area the image of the bottons above are mixed in and everything looks bad. Any idea what I am doing wrong in saving the image? thanks!

    Yes, I see the big ugly squares. They are what appears whenever extremely heavy JPEG compression is applied to a low-resolution image tht has relatively large areas of similar colors. Something somewhere is applying such compression to the pages, or portions of them, that you are viewing in your browser(s). Your MBP is not doing that: it can't. Either the page images (or parts of them) are being compressed by the website owners or, if every web page is affected, they are being compressed by your ISP in the process of being transmitted to you, as Gordito suggests. That would greatly increase the speed of page loading, but at the expense of image quality. You wouldn't see the image degradation on an iPhone or cell phone — the screen is too small — but on the MBP's high-resolution display it would be much more apparent, IF the MBP were receiving the signal in the same highly compressed form as the phone. If the MBP receives the same web pages through an ISP that doesn't over-compress them, they'll look the way they ought to look. So if you are receiving these web pages through a cellular ISP rather than through a broadband connection, take the MBP to a wifi hotspot and connect through wifi instead. I bet things will look different then.
    Compressing images is something a web browser can't do: a browser just displays the signal that comes to it.

  • Draw images in different Panels

    Hi,
    I have a JFrame with three JPanels.
    How can I draw three different Buffered images to those three JPanels?
    Code is appreciated.

    devboris wrote:
    Hi,
    I have a JFrame with three JPanels.
    How can I draw three different Buffered images to those three JPanels?Do you know how to draw one BufferedImage in one JPanel? If not, start there.
    Code is appreciated.An [SSCCE |http://sscce.org] is appreciated.

  • Drawing moving GIF images?

    Is it possible to draw moving gif images on a simple Frame applet?
    I made an image drawer class for my applet and i can draw simple 2d images.
    Here is the basis of my GameSprite class;
        public byte[] pixels;
        public int width;
        public int height;
        public GameSprite(String imageName, int requestIndex) {
         try {
                    // Removed code, it's zipInputStream, but it can be used just as ./image.jpg etc
         javax.swing.ImageIcon icon = new javax.swing.ImageIcon(fileBytes);
         width = icon.getIconWidth();
                     height = icon.getIconHeight();
                     pixels = fileBytes;
         } catch(Exception e) {
              e.printStackTrace();
        public void drawSprite(int x, int y) {
         try {
              Image image = Toolkit.getDefaultToolkit().createImage(pixels);
                                    //Removed code here
              graphics.drawImage(image, x, y + 7, width, height, observer);
         } catch(Exception e) {
              e.printStackTrace();
        }If i try to draw an animated gif image it dosn't move.
    Thanks for any help.

    In Java you need to override the paint method in AWT and paintComponenet method in SWING to do graphics/animation. If you go to an offscreen rendering, then you can paint to the graphics context of an image you use for a drawImage in your paint/paintComponent...
    If you where overriding a Panel in AWT you would override paint:
    public void paint(Graphics g){
      g.drawImage(im, 0, 0, this);
    }Then where you are maipulating your graphics you would do something like this:
    //code snippet
    Graphics g = im.getGraphics();
    //make what ever changes to im by manipulating the graphics context g
    repaint();

  • Drawing images when your class is in a package.

    I have a class in a package. The image I want to draw is in the package, but when I draw it g.drawImage(img, 0, 0, this); it won't draw, even though the image is in the same directory as that class.
    Here is the code:
    package Game;
    import java.awt.*;
    public class SplashScreen extends Frame{
         splashPanel sp;
         public SplashScreen(){
              super("Splash");
              sp = new splashPanel();
              add(sp);               
    class splashPanel extends Panel{
         Image splash;
         public splashPanel(){
              super();
              splash = Toolkit.getDefaultToolkit().getImage("paddle1.gif");
              repaint();          
         public void paint(Graphics g){
              g.setColor(Color.black);
              g.fillRect(0,0,200,200);
              g.drawImage(splash, 0, 0, this);
              System.out.println("Image");
    }

    Still doesn't work.
    package Game;
    import java.awt.*;
    public class SplashScreen extends Frame{
         splashPanel sp;
         public SplashScreen(){
              super("Splash");
              sp = new splashPanel();
              add(sp);               
    class splashPanel extends Panel{
         Image splash;
         public splashPanel(){
              super();
              splash = Toolkit.getDefaultToolkit().getImage("splash.jpg");
              MediaTracker tracker = new MediaTracker(this);
              tracker.addImage(splash, 0);
              try{
                   tracker.waitForID(0);
              } catch (InterruptedException e){}
              repaint();          
         public void paint(Graphics g){
              g.setColor(Color.black);
              g.fillRect(0,0,200,200);
              g.drawImage(splash, 0, 0, this);
              System.out.println("Image");
    }

Maybe you are looking for

  • How do I force an app to stop on iPad 3

    I have an app that is grayscale out and reads downloading.....it looks like pandora but pandora is on another page working fine.   how do I get rid of this app?  it's been in this download mode for days.  it s not REALLY downloading that I can tell. 

  • Syntax error while precompiling query

    Hi, Using dbxml 2.3.8. I get this error when calling the manager's prepare() in PHP : Error: Variable :state does not exist [err:XPST0008], <query>:76:98 The (simplified) xquery looks like: " ... (doc("...")/*[1],$state)" I want $state to be a variab

  • New Ipod Mini (2nd Generation) Unrecognized by Windows XP Pro

    I'm beside myself with frustration after two days of trying to get this to work. Three XP Pro computers tell me "USB Device not recognized - One of the USB devices attached to this computer has malfunctioned - Windows does not recognize it. For assis

  • Whats the difference between the Canvas types?

    When i start the layout wizard and i choose to make a new carvas, there are several types of canvas available: Content, Stacked, Vertical toolbar, Horizontal toolbar, Tab What is the difference between these types? I have tried making different types

  • Reverse the sort output for autofeed copying??

    is there a way to "reverse" the output for copying when using the autofeed tray? i sometimes copy 20+ page documents and every time i do this i get the first page face up and then the second page comes out face up and then the third so that i have to