Help me get my image/Ellipse to paint

Hi: I am currently using Ellipse, and I am starting the basic steps for what will soon be a mini-like game. I need to make an Ellipse and put and image over it. Then make it moves on the x,y, axis using arrow keys.
I have had numerous people tell me that my code is fine, and that the Ellipse shows up for them, but I have tried for so long and still cannot get it to paint. I have the image in my projects folder, yet the Ellipse/image wont show whenever I go in Applet viewer. It is simply a blank white screen. I have 2 parts to my project....Bullet.java (contains the actual creating of the Ellipse) and myApplet.java(contains the Graphics g etcetc)
First is Bullet.java:
import java.awt.*;
import java.awt.geom.*;
public class Bullet {
      private Image picture;
      private int xpos, ypos, height, width, speed, xdir, ydir;
      private Ellipse2D.Double c;
      public Bullet(Image p, int x, int y, int w, int h, int s, int xd)
       picture = p;
       xpos = x;
       ypos = y;
       width = w;
       height = h;
       speed = s;
       xdir = xd;
       ydir = 0;
       c = new Ellipse2D.Double (xpos, ypos,  width,  height);
      public void move()
       xpos = xpos + speed*xdir;
       ypos = ypos + speed*ydir;
       c.setFrame(xpos, ypos,  width,  height);
      public int getX() { return xpos;}
      public int getY() { return ypos ;}
      public int getHeight() { return height; }
      public int getWidth() { return width ;}
      public int getXDir() { return xdir ;}
      public int getYDir() { return ydir ;}
      public void setPos(int a, int b) {xpos = a; ypos = b;}
      public void setDir(int x, int y)
       xdir = x;
       ydir = y;
      public boolean intersects(int x, int y, int w, int h)
       return c.intersects(x, y, w, h);
      public void displayBullet(Graphics2D g)
       g.drawImage(picture, xpos, ypos, width, height, null);
      public void paint(Graphics2D g)
       displayBullet(g);
       g.fill(c);
}and here is myApplet.java
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.*;
import javax.swing.*; 
import java.awt.image.*;
public class myApplet extends Applet implements KeyListener
     BufferedImage imageBuffer;
      Graphics2D  graphicsBuffer;
      private  Bullet s;
      private Timer t;
      Image p;
public void init()
  imageBuffer = (BufferedImage)createImage(getWidth(), getHeight());
  graphicsBuffer = (Graphics2D) imageBuffer.getGraphics();
  p= getImage(getCodeBase(), "dot.jpg");
  s=new Bullet(p, 20, 250, 50, 200, 20, 0);
  addKeyListener(this);
  setFocusable(true);
  for(int j=0;j<5;j++)
   for(int k=0;k<16;k++)
        p= getImage(getCodeBase(), "dot.jpg");
ActionListener z = new ActionListener()
  public void actionPerformed(ActionEvent evt)
   s.move();
paint(graphicsBuffer);
t=new Timer(10, z);
t.start();
public void keyPressed(KeyEvent e)
if (e.getKeyCode() == KeyEvent.VK_DOWN)
  s.setDir(0,1);
if (e.getKeyCode() == KeyEvent.VK_UP)
  s.setDir(0,-1);
if (e.getKeyCode() == KeyEvent.VK_LEFT)
  s.setDir(-1,0);
if(e.getKeyCode() ==KeyEvent.VK_RIGHT)
  s.setDir(1,0);
public void keyReleased(KeyEvent e)
if (e.getKeyCode() == KeyEvent.VK_DOWN)
  s.setDir(0,0); 
if (e.getKeyCode() == KeyEvent.VK_UP)
  s.setDir(0,0);
if (e.getKeyCode() == KeyEvent.VK_LEFT)
  s.setDir(0,0);
if(e.getKeyCode() ==KeyEvent.VK_RIGHT)
  s.setDir(0,0);
public void keyTyped(KeyEvent e) {} 
public int width = 3000;
public int height= 300;
public void paint(Graphics g)
Graphics2D g2 = (Graphics2D) g;
graphicsBuffer.setColor(Color.white);
graphicsBuffer.fillRect(0, 0, getWidth(), getHeight());
graphicsBuffer.setColor(Color.blue);
s.paint(graphicsBuffer);
g2.drawImage(imageBuffer, 0,0, getWidth(), getHeight(), this);
     private static final long serialVersionUID = 1L;
}

XNOCTISX wrote:
Hi: I am currently using Ellipse, Sorry, do you mean Eclipse? It took me a few seconds to realize that's not what this word was. Maybe I'm getting old and need to increase my font size.
You are doing a few things that I don't understand.
Why are you using getGraphics? That's almost definitely not what you want.
graphicsBuffer = (Graphics2D) imageBuffer.getGraphics();Have you confirmed that this works as expected?
p= getImage(getCodeBase(), "dot.jpg");Why:
for(int j=0;j<5;j++)
for(int k=0;k<16;k++)
p= getImage(getCodeBase(), "dot.jpg");
}Again, why? I'm not extremely familiar with applets, but shouldn't this be a call to repaint() or something of the sort? Or better yet, why don't you use a JPanel (and a JApplet) and do the painting there?
paint(graphicsBuffer);This doesn't look right to me at all. Why are you using graphicsBuffer instead of g?
public void paint(Graphics g)
Graphics2D g2 = (Graphics2D) g;
graphicsBuffer.setColor(Color.white);
graphicsBuffer.fillRect(0, 0, getWidth(), getHeight());
graphicsBuffer.setColor(Color.blue);
s.paint(graphicsBuffer);
g2.drawImage(imageBuffer, 0,0, getWidth(), getHeight(), this);
}I think you should take a careful look at the painting and drawing tutorials (here's [another |http://download-llnw.oracle.com/javase/tutorial/uiswing/painting/index.html] one).
If, after reading both of those tutorials, you still have questions, try posting an [SSCCE |http://sscce.org] (without all that extra stuff in it, and preferably not an applet) that demonstrates the problem.

Similar Messages

  • Help to get better image from cctv

    hi,
    not an expert at all with photoshop use it for basic image and 3d text creation for sites.
    i have cctv footage of my car being vandalised and i want to somehow use photoshop to take an image but is there anyway i can manipulate it to get a better look of car or people in it?
    file is avi so can take screenshot but i want try get them caught.
    any help greatly greatly appreciated.
    many thanks

    People ask this kind of question here from time to time.  I'm sorry to hear your car was vandalized.
    Feel free to post a representative still for a more thorough answer, but be ready to hear that miracles usually don't happen with low quality surveillance video images.
    The human eye / brain combo is better at "seeing" into bad images than almost any software, and if you can't tell in the moving picture who they are then quite likely no amount of image enhancement on individual frames is going to improve recognizability.
    -Noel

  • Help in Getting Archived Images Organized Before Import

    I'm a LR beginner and need advice. I have about 3000 tiff and psd images - about 75Gb, archived on CD and DVD in pretty random order. They aren't on my hard drives. I've kept track of them through iView. Now I want to bring them into Lightroom and use it rather than iView for keeping track of them. I'm also coming to recognize that keeping them online on an external HD is probably a good thing also.
    I'm thinking I should get an external HD (250Gb or so) and copy from CD/DVD back to that device. Then organize them into folders in some way that makes sense. Then once I've done that, import them into LR and tag them with keywords. Then split out further into collections.
    Does this make sense? I'd appreciate your thoughts and experiences.
    Thanks
    Brad

    Obviously you are going to get much better import performance if your images are on a HD rather than a CD/DVD.
    You don't say if you're using Mac or PC, but if it's a Mac, you can do what I am doing. I had previously archived my images to CD and DVD. I use the Mac's Disk Utility program to create a copy of the disk image on the external HD. Then I mount that and have LR import from the disk image.
    What this means is that I can use either the original CD/DVD or the external HD files. Once I mount the volume, LR will find the images (red folders come online). This way you have your backup automatically on CD or HD and if you are mobile, you can take either media with you. At home base all your images are on the HD, just a mount away.
    If you do this, when creating the disk image in Disk Utility, make sure to choose the 'CD/DVD Master' setting (rather than compressed or other options) because they mount much faster.
    Again, this is all the way Mac works, not something specific to LR. I don't know of a Windows equivalent, but there may be something out there.
    This doesn't help you with reorganizing as part of your import process, but keywording and collections could do that regardless of the location of the files.

  • Help with getting Images to show in a Rock, Paper, Scissors game

    Hi
    I am working on this Rock, paper, scissors java game and the program works, but I can not figure out how to get the images to load onto the program. So my question is how do I get the images to load up with the program? I am using JCreator for this project. I have created the Basic Java Application project, and then added in the 3 .java files that I need to run the program, but I just can not figure out how or where I need to upload the files. The game works without the images, but I would really like them to show up.
    This is the .java file that calls up the images:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class pss extends JPanel implements ActionListener, ItemListener
    private final Color clrBackground = new Color(163,243,255);
    private final Color clrForeground = new Color(0,0,0);
    private JComboBox cboxWeapon;
    private JTextField txtCPUWeapon, txtWins, txtLoses, txtDraws;
    private JLabel lblPlayerWeapon, lblCPUWeapon, lblWins, lblLoses, lblDraws, lblStatus, lblPlayerWeaponIcon, lblCPUWeaponIcon;
    private JButton cmdPlay, cmdReset;
    private ImageIcon[] imgWeapon;
    private JPanel panRoot, panPlayerArea, panPlayerWeapon, panCPUArea, panCPUWeapon, panStatusArea, panGo, panCounters, panWins, panLoses, panDraws;
    private pssEngine engine = new pssEngine();
    private objCreateAppletImage createImage = new objCreateAppletImage();
    private boolean errorWithImages = false;
    public static void main(String[] args) //With applications, you have to specify a main method (not with applets)
    JFrame.setDefaultLookAndFeelDecorated(true); //Make it look nice
    JFrame frame = new JFrame("Paper Stone Scissors"); //Title
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setResizable(false); //Stops the user resizing the window
    JComponent paneMain = new pss();
    paneMain.setOpaque(true);
    paneMain.setPreferredSize(new Dimension(420,350));
    frame.setContentPane(paneMain);
    frame.pack();
    frame.setVisible(true);
    public pss ()
    cboxWeapon = new JComboBox(engine.getWeapon());
    cboxWeapon.addItemListener(this);
    txtCPUWeapon = new JTextField(engine.getStrCPUWeapon(), 5);
    txtWins = new JTextField("0", 5);
    txtLoses = new JTextField("0", 5);
    txtDraws = new JTextField("0", 5);
    txtCPUWeapon.setEditable(false);
    txtWins.setEditable(false);
    txtLoses.setEditable(false);
    txtDraws.setEditable(false);
    lblPlayerWeapon = new JLabel("Choose your weapon", JLabel.CENTER);
    lblCPUWeapon = new JLabel("The CPU's weapon", JLabel.CENTER);
    lblWins = new JLabel("Amount of wins:", JLabel.RIGHT);
    lblLoses = new JLabel("Amount of loses:", JLabel.RIGHT);
    lblDraws = new JLabel("Amount of Drawss:", JLabel.RIGHT);
    lblStatus = new JLabel("", JLabel.CENTER);
    lblPlayerWeaponIcon = new JLabel("", JLabel.CENTER);
    lblCPUWeaponIcon = new JLabel("", JLabel.CENTER);
    lblPlayerWeaponIcon.setPreferredSize(new Dimension(150,150));
    lblCPUWeaponIcon.setPreferredSize(new Dimension(150,150));
    cmdPlay = new JButton("Go!");
    cmdReset = new JButton("Restart");
    cmdPlay.addActionListener(this);
    cmdReset.addActionListener(this);
    try
    imgWeapon = new ImageIcon[3];
    for (int i = 0; i < 3; i++)
    imgWeapon[i] = createImage.getImageIcon(this, ".src/images/" + engine.getWeapon(i) + ".gif", "Icon for " + engine.getWeapon(i), 13000);
    lblPlayerWeaponIcon.setIcon(imgWeapon[0]);
    lblCPUWeaponIcon.setIcon(imgWeapon[0]);
    catch (Exception ex) //The game works without the images, so carry on
    errorWithImages = true;
    setLayout(new BorderLayout());
    panRoot = new JPanel(new BorderLayout());
    panPlayerArea = new JPanel(new BorderLayout());
    panPlayerWeapon = new JPanel(new BorderLayout());
    panCPUArea = new JPanel(new BorderLayout());
    panCPUWeapon = new JPanel(new BorderLayout());
    panStatusArea = new JPanel(new BorderLayout());
    panGo = new JPanel();
    panCounters = new JPanel(new GridLayout(3,1,2,2));
    panWins = new JPanel();
    panLoses = new JPanel();
    panDraws = new JPanel();
    add(panRoot, BorderLayout.CENTER);
    panRoot.add(panPlayerArea, BorderLayout.WEST);
    panPlayerArea.add(panPlayerWeapon, BorderLayout.NORTH);
    panPlayerWeapon.add(lblPlayerWeapon, BorderLayout.NORTH);
    panPlayerWeapon.add(cboxWeapon, BorderLayout.SOUTH);
    panPlayerArea.add(lblPlayerWeaponIcon, BorderLayout.SOUTH);
    panRoot.add(panCPUArea, BorderLayout.EAST);
    panCPUArea.add(panCPUWeapon, BorderLayout.NORTH);
    panCPUWeapon.add(lblCPUWeapon, BorderLayout.NORTH);
    panCPUWeapon.add(txtCPUWeapon, BorderLayout.SOUTH);
    panCPUArea.add(lblCPUWeaponIcon, BorderLayout.SOUTH);
    panRoot.add(panStatusArea, BorderLayout.SOUTH);
    panStatusArea.add(panGo, BorderLayout.NORTH);
    panGo.add(cmdPlay);
    panGo.add(cmdReset);
    panGo.add(lblStatus);
    panStatusArea.add(panCounters, BorderLayout.SOUTH);
    panCounters.add(panWins);
    panWins.add(lblWins);
    panWins.add(txtWins);
    panCounters.add(panLoses);
    panLoses.add(lblLoses);
    panLoses.add(txtLoses);
    panCounters.add(panDraws);
    panDraws.add(lblDraws);
    panDraws.add(txtDraws);
    panRoot.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    setBackground(clrBackground);
    panRoot.setBackground(clrBackground);
    panPlayerArea.setBackground(clrBackground);
    panPlayerWeapon.setBackground(clrBackground);
    panCPUArea.setBackground(clrBackground);
    panCPUWeapon.setBackground(clrBackground);
    panStatusArea.setBackground(clrBackground);
    panGo.setBackground(clrBackground);
    panCounters.setBackground(clrBackground);
    panWins.setBackground(clrBackground);
    panLoses.setBackground(clrBackground);
    panDraws.setBackground(clrBackground);
    lblPlayerWeapon.setForeground(clrForeground);
    lblCPUWeapon.setForeground(clrForeground);
    lblWins.setForeground(clrForeground);
    lblLoses.setForeground(clrForeground);
    lblDraws.setForeground(clrForeground);
    txtWins.setForeground(clrForeground);
    txtLoses.setForeground(clrForeground);
    txtDraws.setForeground(clrForeground);
    txtCPUWeapon.setForeground(clrForeground);
    public void reset ()
    cboxWeapon.setSelectedIndex(0);
    lblStatus.setText("");
    engine.reset();
    public void actionPerformed (ActionEvent e)
    if (e.getSource() == cmdReset)
    reset();
    else
    lblStatus.setText(engine.play(cboxWeapon.getSelectedIndex()));
    txtCPUWeapon.setText(engine.getStrCPUWeapon());
    txtWins.setText(Integer.toString(engine.getWins()));
    txtLoses.setText(Integer.toString(engine.getLoses()));
    txtDraws.setText(Integer.toString(engine.getDraws()));
    if (!errorWithImages)
    lblCPUWeaponIcon.setIcon(imgWeapon[engine.getCPUWeapon()]);
    public void itemStateChanged (ItemEvent e)
    if (!errorWithImages)
    lblPlayerWeaponIcon.setIcon(imgWeapon[cboxWeapon.getSelectedIndex()]);
    }Here is the other .java file that calls on the Images:
    import java.awt.*;
    import java.io.*;
    import javax.swing.ImageIcon;
    public class objCreateAppletImage
    public void objCreateAppletImage ()
    //If an error occurs (or is thrown by me) it will be thrown to the next level up, and either caught or thrown
    public ImageIcon getImageIcon (Object parentClass, String path, String description, int fileSize) throws Exception
    int count = 0;
    BufferedInputStream imgStream = new BufferedInputStream(parentClass.getClass().getResourceAsStream(path));
    byte buff[] = new byte[fileSize];
    if (imgStream == null) //If doesn't exist
    throw new Exception("File not Found");
    try
    count = imgStream.read(buff);
    imgStream.close(); //Closes the stream
    catch (IOException ex)
    throw new Exception("Corrupt file");
    return new ImageIcon(Toolkit.getDefaultToolkit().createImage(buff), description); //Creates the image from the byte array
    }Could someone please help me? I really have no idea and I would like this to work.
    Thank you
    Frank

    Oh, thank you. I will not do that in the future.
    I am not entirely sure how I would use the getImage method in an Applet. I would prefer to just use the code that I have currently, unless the addition of making the program an Applet only adds a small amount of code. But then even still, I am not entirely sure what I would write in the .class file to make the images load. And then I would not really know how to properly incorporate the pss.java file and the .class file together so they read off of each other.

  • Tried to install the latest update on my ipad. i get an image of "itunes" with a connecting cord. hasnt changed in three hours. if i turn it off, it goes right back to same image on black background. i am stuck, please help me, thanks

    i tried to install the latest update on my ipad. i get an image which says I tunes with a cord to plug in. it is on a black background.. it has been like this for three hours now. if i turn it off and then on again that is the only page that appears. i am stuck. please can anyone help me? thanks.

    It's too bad you lost stuff. I would recommend that you back stuff up before the next one. For example, iOS8 will be out sometime this fall. Just in case you experience the same thing again, do a backup before you do the update.

  • Need help with getting images to look smooth (without the bitmap squares) around the edges. When I transfer the image from pictures, it sets itself into the InDesign layout, but with square edges. I need to find out how to get it to look smooth?

    Need to find out how to get my images transferred into an InDesign layout without the rough edges, as with a bit map image, but to appear with smooth edges in the layout. I can notice it more when I enlarge the file (pic). How can I get it to appear smooth in the finished layout. Another thing too that I noticed; it seems to have effected the other photos in the layout. They seem to be
    pixelated too after I import the illustration (hand drawn artwork...)? Any assistance with this issue will be greatly appreciated. Thanks in advance.

    No Clipboard, no copy & paste, as you would not get the full information of the image.
    When you paste you can't get the image info from the Links panel, but you can get resolution and color info either via the Preflight panel or by exporting to PDF and checking the image in Acrobat.
    Here I've pasted a 300ppi image, scaled it, and made a Preflight rule that catches any image under 1200ppi. The panel gives me the effective resolution of the pasted image as 556ppi. There are other workflow reasons not to paste—you loose the ability to easily edit the original and large file sizes—but pasting wouldn't cause a loss in effective resolution or change in color mode.

  • Need help in displaying an Image in a JLabel

    Hi everyone,
    I am using a JLabel to display images on a particular screen. I am facing some problem while doing so..
    On my screen there are images of some garments. When the users select colors from a particular list, i should color this garment images and load it on the screen again with the colors. I have a floodfill class for filling the colors in the images. The problem I am facing is I am able to color the image properly with my floodfill class but when displaying the image on the same jlabel, the image gets distorted somehow.
    Everytime I color the image, I create an ImageIcon of the image and use the seticon method from the JLabel class. First I set the icon to null and then set it to the imageicon created. here is the code I use.
    If 'image' is the the image i have to load
    ImageIcon imgicon = new ImageIcon(image);
    jlabel.setIcon(null);
    jlabel.setIcon(imgicon);I am setting the icon to null because I have not found any other method to clear the previous image from the jlabel.
    Can anyone who has worked on images before and faced a similar situation help me with this?? Is there some other container I can use besides the JLabel to display the images perhaps?
    Thanks in advance.....
    Bharat

    And the thing is when I first go into that screen with the selected colors it is displaying the images perfectly.
    It is only giving problems when I pick different colors on the screenit really sounds like the problem is in your floodfill class.
    I have no idea what's in floodfill, but if you were e.g. using a JPanel and paintComponent,
    you would need to have as the first line in paintComponent()
    super.paintComponent(..);
    to clear the previous painting.
    if not, you would be just drawing over the top of the previous paintComponent(), and if the calculation of the
    painting area is not 100% exact, you may get the odd pixel not painted-over, meaning those pixels will display
    the old color.

  • Help with saving my image as text

    Hi,
    I have to submit my Java project tomorrow and as part of it we must build a density map and save the image as a text file. I have the programme working fine however I can't seem to get the image to save properly as a text file.
    Basically I have to read in a raster 300 by 300 text file filled with 0 values and one 255 which is where a bomb explodes. I get the x and y positions of this after turning it into a 2d array, then move a number of bacteria particles around and then build a density map which in a 1d int array.
    I now want to save my new image that shows where the particles landed in a SaveMapMenuListnr class and I tried to use a previous practical's SaveGreyMenuListnr (which converted an image to greyscale when it saved it) class to help me with this but now I am in a mess with it as you can see from the below code! All i want to do is save what I have on the screen into a text file and hopefully retain the image on the screen as it is but I have no idea whether to use the 2d array or 1d array and whether the code I have (and which parts of it) is of any use.
    Please see below code, thanks.
    // Declares a new class called SaveMapMenuListnr and implements ActionListener
    public class SaveMapMenuListnr implements ActionListener {
            // Declares a global integer variable to store the compressedInt values
            int compressedInt;
            // Makes an object of ButList and sets it to null
            ButList arrayValues = null;
            // Creates a private object of DisplayPanel and sets it to null
         private DisplayPanel panel = null;
            // Declares a new instance of SaveMapMenuListnr and passes in the DisplayPanel and ButList objects
         public SaveMapMenuListnr (DisplayPanel pn, ButList bl) {
              panel = pn;
                    arrayValues = bl;
         } // End of instance
           // This method is invoked to read in an image when the Action Event occurs
         public void actionPerformed (ActionEvent ae) {
            // These methods get copies of the 2D and 1D int arrays from the arrayValues object of the ButList class
            int [][] gotDensity = arrayValues.getDensity();
            int [] gotOneDintArray = arrayValues.getOneDintArray();
            // Builds a file dialog and shows it on the screen
         FileDialog saveDialog = new FileDialog(new Frame(), "Save file", FileDialog.SAVE);
         saveDialog.setVisible(true);   
            // Sets the save file equal to the chosen directory and the open file
            File file = new File(saveDialog.getDirectory() + saveDialog.getFile());
            // Creates a null object of FileWriter
            FileWriter fileWriter = null;
            // Creates a new bombMap image
            Image bombMap = null;
            // Sets bombMap equal to the image on display in the panel
            bombMap = panel.getDisplayImage();   
            // Gets the width and height of the image
            int width = bombMap.getWidth(panel);
            int height = bombMap.getHeight(panel);
            try {
            fileWriter = new FileWriter(file);
            for (int i = 0; i < 300; i++) {
                Color color = new Color(gotOneDintArray);
    int red = color.getRed();
    int green = color.getGreen();
    int blue = color.getBlue();
    double temp = 0.56 * (double)green + 0.33 *(double) red + 0.11 *(double) blue;
    color = new Color((int)temp,(int)temp,(int)temp);
    int compressedInt = color.getRGB();
    String grey = String.valueOf (temp);
    fileWriter.write(grey + " ");
    gotOneDintArray[i] = compressedInt;
    fileWriter.close();
    catch(IOException f) {
    f.printStackTrace();
    bombMap = panel.getToolkit().
    createImage(new MemoryImageSource(width, height, gotOneDintArray, 0, width));
    // This sets "bombMap" as the DisplayImage and instructs the paint method in the Image Panel class file to repaint
         panel.setDisplayImage(bombMap);
         panel.repaint();
    } // End of ActionPerformed method
    } // End of class

    I don't understand the question. What kind of format do you expect the text file to have?

  • To get an image of a pure JFrame

    I wish to get an image of a pure JFrame.I am able to creat a jpeg file but there is a problem, the shapes that are drawn dont appear in the file created file. Below is my code ,can someone help me...
    import javax.imageio.*;
    import javax.swing.*;
    import java.io.File;
    import java.io.IOException;
    import java.awt.image.*;
    import java.awt.*;
    public class Filesave
         void saveToFile(Frame source, File target) throws IOException
              int w = source.getWidth();
                 int h = source.getHeight();
                 int type = BufferedImage.TYPE_INT_RGB; //or another type
                BufferedImage image = new BufferedImage(w, h, type);
               Graphics2D g2 = image.createGraphics();
              / /You may want to blank this out, if your source doesn't draw
              //all its pixels:
              //g2.setPaint(source.getBackground());
             Color transparent = new Color(255, 255, 255, 255);
             g2.setColor(transparent);
                g2.setComposite(AlphaComposite.Src);
             g2.fillRect(0,0,w,h);
             //main call:
             source.paint(g2);
             //or call paintComponent instead, to avoid drawing border
             g2.dispose();
             //ImageIO.write(image, "jpeg", target);
             ImageIO.write(image, "bmp", target);
             image.flush(); //currently implemented with {}
    }With thanks in advance...

    You're telling the source to paint to g2, then immediately after that you dispose g2 without doing anything with it. Don't you need to set your image reference to g2's image before writing it to the file?
    Or maybe I misunderstand and g2 IS the graphics of image. So maybe it's just that you need to write image to the file before you dispose g2?

  • I have a macbook pro, a mini display port to hdmi cable to hook up to my tv (a toshiba 1080p flatscreen).  what do I do to actually get the image on the tv screen?  Do I need another cable for sound?

    I am trying to watch a tv show that I purchased into I-tunes.  I have the cable and it hooks to the TV okay.  The TV shows the regular apple screen that looks like the universe screen - like when it boots up or is doing an upgrade on the OS.  I can't get the image to go from the laptop to the TV.  I tried under displays and it shows the TV as a display but I can't get the image on the TV.......Please help.

    Rwogera wrote:
    I couldn't transmit sound either, do i need another cable like Kim said? i mean it cant be transmitted through this HDMI port? as for me i have one of the latest mac pro with intel core i5..tnx
    I need to know which MacBook Pro you have.  Only mid-2010  and later MBP's transmit sound through MiniDisplay Port to HDMI.  I have no information about the Mac Pro, so you might want to go to that Forum and ask there.

  • How Do I get icons image directory to work in a JAR file?

    Yes, I must admit after going through the tutorial and other stuff I am stiil stumped
    I have an application that uses the jlfgr icons for the toolbar, and it works fine as long as i actually run it from the directory that it is in.
    I would like to put in into a jAr file, and be able to execute it from other places.
    I have a Directory named PhoneBook
    in that are the classes I use
    AddressBook - the main class
    PersonEntry - The 'data class'
    and various other things like FileFilters.....
    inside that directory there are two more:
    images - contains all the icon images
    Data - where the default 'database' entries are stored.
    I use code like this:
         private void fillToolBar( JToolBar bar )
              Dummy = new JButton(new ImageIcon("images/New16.gif"));
              Dummy.setActionCommand("New");
              Dummy.addActionListener(this);
              Dummy.setToolTipText("New");
              bar.add( Dummy );
              // etc etc
    to get all the icons into the toolbar
    I have made a Jar file that has all the classes and all the directorys with the icons in it
    and so the program runs, but does not get the icons for the toolbar, I just get a whole load of 'dud' buttons.....
    AS this is the first time i've ever got the GUI to look right rather than just the code functioning properly
    I'd like to get the whole thing in a working Jar file
    So Could someone show me Step By Step, How I get my classes and images into a Jar file
    so that i can from a different directory go
    java - jar Phone.jar
    and have the GUI come up with all the images, assuming I'm totally thickheaded when it comes to Jar files.?
    I also can't get the images to show up if I merely run the 'program' from another directory than the one it is compiled in
    I can get the program to run, just not access the images with something like
    java -cp blah/blah/blah AddressBook
    {the main class is AddressBook }
    the data directory can be anywhere as I use a JFileChooser to allow the user to open and save desired files.
    I really would appreciate some clear workable help. {though I'm running out of Duke Dollars...}

    What you need is a correct path to the directory
    inside of the jar. This can be accomplished by adding
    a line to your main program like this:
    URL
    url=myProgram.class.getResource("images/New16.gif");
    Dummy = new JButton(new ImageIcon(URL));
    where myProgram.class is the name of the class
    file that contain the main method.
    Hope this helps....
    ;o)
    PS: I don't want your dukes...I got them coming out of
    my ears!
    O.K, that works thank you.
    I put something like:
    for all the 'buttons' in the toolbar
    URL url = null;
    Class ThisClass = this.getClass();
    url=ThisClass.getResource("images/New16.gif");
    Dummy = new JButton(new ImageIcon(url));
    Dummy.setActionCommand("New");
    Dummy.addActionListener(this);
    Dummy.setToolTipText("New Database");
    bar.add( Dummy );
    etc for all the rest of the 'buttons'
    After Reading the API docs on URL's etc I'm still not sure as to why it works, but it does....
    I am able now to place the class files in a jar along with the images and it all works fine
    although now I don't quite follow all my code....................
    I assume that
    url=ThisClass.getResource("images/New16.gif");
    returns some sort of 'relative url ' ???
    Thanks for the help though.

  • Problem in getting the image through URL

    hi all,
    I facing the problem,Inwhich i am unable find the solution...I am using the following code to display the image
    public void doGet(HttpServletRequest request,HttpServletResponse response)
                        throws IOException, ServletException {
                   int data=0;
                   response.setContentType("image/png");
                   ServletOutputStream out = response.getOutputStream();
                   String file = request.getContextPath()+imageNames[0];
                   //String file = "C:/Program Files/Apache Group/Tomcat 4.1/webapps/ImageComm/WEB-INF/images"+imageNames[index];
                   BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
                   System.out.println("the size of the inputStream is..."+in.available());
                   System.out.println("the context path is..."+request.getContextPath());          
                   while ((data = in.read()) != -1) {
                   out.write(data);
    with the above i am not getting any error at the compile time but it was giving exception like FileNotFoundException.
    but the same thing(URL address) when i am copying on the browser it was displayig the image.
    (what might be the reason)
    one more thing when i commented on the url address and try to use the actual realpath address it was displaying the image with out any problem
    can anybody give me the solution like where to keep my images by which i can able to get the images through url address
    thanks in advance
    lakshman

    hi all,
    I am getting the image from the server.but the problem is i am getting the Exception as ArrayOutOfBound exception.
    It was displaying the Image for the first time.and when ever it was going for the second time in to the paint method it was displaying the IOException in reading the stream from the connection.
    can anybody give me the solution in rectifying that exception.
    thanks in advance
    lakshman

  • HELP: Cannot restore DMG image stored on NTFS disk!

    Hello. My MacBook Pro has OSX Lion on it.
    I have created a DMG image of my starting volume using Disk Utility. The image was saved on an NTFS formatted external USB disk. I used Paragon NTFS for Mac to activate writing on NTFS partitions. The image was created, tested and it mounted fine. It's size is 105GB.
    I have restarted the system and am accessing Disk Utility from the recovery partition that OSX Lion creates. Disk Utility can see the NTFS disk and I can choose the DMG image as source and the partition on the internal hard disk as a target without problems but when I press the restore button and the Image scan process is going to start I just get an error that says "Unabke to scan Mac-OSX HD. Resource busy". When I try the SCAN BEFORE RESTORE command on Disk Utility on the image I am getting "Unable to scan MAC IMAGE.DMG (Not such file or directory)".
    I have already erased my startup disk and really need to get this image back in place. It is the only backup I have of my data.
    Any help is greatly appreciated!

    Thanks for the fast answer. Excuse my question but are you certain of this? This would be a big job because I would have to:
    1. Find another external hard disk. Most probably it will be NTFS formatted because this and FAT32 are the most common formats out there.
    2. Find another apple computer to transfer the image to the other hard disk
    3. Format my external hard disk as a HFS disk
    4. Transfer the DMG image back to the HFS hard disk.
    5. After this reformat my external hard disk as NTFS because I live in an hybrid world where PCs and Macs coexist and NTFS is a good bet for compatibility.
    If you indeed are certain that that is the correct answer to this situation then I will move into it immediately.
    Thanks.

  • How to get the image in docking control  in a report using doc management

    HI All
    My question is that is that i am storing one image using documents in jha2n.
    Now I want to get that image in report using Document management.
    Pls guide how to proceed as I am new and dont know anything about document management.
    Thanks
    Pooja

    Hi,
    Please kindly refer to the online help link below:
    [http://help.sap.com/saphelp_erp60_sp/helpdata/en/7a/973035624811d1949000a0c92f024a/frameset.htm|http://help.sap.com/saphelp_erp60_sp/helpdata/en/7a/973035624811d1949000a0c92f024a/frameset.htm]
    And for handling the DMS document, you may check the BAPIs in SAP Note: 504692
    Function group: CVBAPI
    BAPI_DOCUMENT_GETDETAIL2
    BAPI_DOCUMENT_CREATE2
    BAPI_DOCUMENT_CHANGE2
    BAPI_DOCUMENT_DELETE
    For display image in the docking control, pleae kindly refer to the SAP DEMO: RSDEMO_DOCKING_CONTROL
    Cheers,

  • I am able to get color images in the continues shot but when i try to snap a color image which i need for my processing i get only a monocrome image

    I have been using lv_vfw.llb VI's for grabbing images from a CREATIVE WEB CAM ,i am able to get color images in the continues shot but when i try to snap a color image which i need for my processing i get only a monocrome image ,i have been trying to play around with the RGB weightings but i am unable to get a color iamge,it shall be of great help if you could help me in doing this as it is urgent for me.Thanks for your help.

    vicky,
    I am unfamiliar with the lv_vfw.llb, and have not used it before. However, I noticed that you stated that you are able to grab in color, just not snap in color. If this is the case, why not just perform a grab and then extract a single buffer from this grabbed data, which would likely be in color? This seems like a possible solution to the issue that you are seeing.
    Other than that, I really don't know enough about the lv_vfw.llb to be of much help on this issue. Hopefully another member of this forum will be able to assist you with this software.
    Regards,
    Jed R.
    Applications Engineer
    National Instruments

Maybe you are looking for