JPG or GIF on GUI

Hello!
Does anyone know how i could show an image in a java.awt frame? (no swing)
Thank you very much!!!

Hi,
a very strange thing happened, i found a way to do it, based on a combination of both of your answers, and it worked... at least, 3 times it did. Now my getGraphics() method returns null!!???
and it doesn't draw anything anymore ofcourse :(
class GUI extends Frame implements ActionListener, TextListener
        protected Image PICTURE = null;
        public GUI()
            PictureViewer("1.JPG",50,600);
        public void PictureViewer(String strFilename, int x, int y)
          if(strFilename.length() < 1)
               System.out.println("USAGE: java PictureViewer <filename>");
          try
               Toolkit toolkit = Toolkit.getDefaultToolkit();
               PICTURE = toolkit.getImage(strFilename);
               Graphics g = this.getGraphics();
               System.out.println("graphics = " +g);
               paint(g,x,y);
          catch(Exception e){System.out.println("Error at drawing picture");e.printStackTrace();}
     public void paint(Graphics g,int x, int y)
          if(g != null && PICTURE != null)
               g.drawImage(PICTURE,x,y,this);
}Is there something wrong?
Thanks allready!

Similar Messages

  • Jpg,gif, and gui's

    hey guys, I just started learning to code gui's... but my book is vague about inserting jpg or gif.....
    I was using:
    ImageIcon b = new ImageIcon("board.jpg");
    I keep getting a blank canvas..
    Can someone help me with siimple code for making a gui with just a picture in it
    thx

    @OP...
    1) The convention used in your sample code assumes
    that the image source file is in the executing
    directory or classpath.... if not you will need to
    provide the full path...
    eg: "C:/Some
    Directory/SomeOtherDir/Myimage.jpg/.gif/,png"or in a directory off the root:
    root-
    /images
    /classes
    /com
    /whatever
    Then ImageIcon icon = new ImageIcon("images/myImage.gif"); will load
    >
    2) If the Image is large, (not in size only, btw),
    you need to use an ImageTracker or you could resort
    to the
    Toolkit.getDefaultToolkit().getImage("somePath")
    method to ensure that the Image is loaded to
    completion prior to the gui being rendered.. any
    delays will see the ImageIcon being updated after the
    gui is rendered, naturally producing no image.....
    ImageIcon uses a ImageTracker to load images

  • Can I open a PDF and save it as a JPG or GIF?

    I asked on the PageMaker forum about creating a jpg or gif of a book cover I created in PageMaker. The suggestion was to create a pdf of it (no problem), open it in PhotoShop, then save it in the format I need. I don't own PhotoShop, so downloaded the Album Starter Edition. For the book cover with photos on it, only the photos are imported; for the book cover with only text and solid-color boxes, nothing at all is imported. Does anyone know how to get the entire pdf into PhotoShop so it can be saved, intact, as a jpg or gif? Thanks!

    I think Downloader in PSE organizer has capabilty to extract images from PDF.
    Collin- Is there any other way in PSE to extract images from PDF. Pls tell us how hat can be done.

  • How to deal with addition of .jpg or .gif file

    how do i add a LARGE .jpg or .gif image to a JPanel? and is it possible to add JTextField or other features onto the .jpg or .gif file after the addition of the image?
    Thanks for the time and consideration.

    If you want the image to just be the background for a panel then you will need to subclass JPanel and override the paintComponent(Graphics) method. In the paintComponent(Graphics) method you will need to draw the image yourself using the Graphics.drawImage() method. For loading the image I would suggest using one of the ImageIO.read() methods.

  • How do I change "save image" to save as jpg or gif rather than an html pointer to the image?

    When I try to download images it is saving them as an HTML file instead of the actual image. I want to save images in their native jpg or gif formats as they are on the web. Downloading wallpapers for example is not possible. Without this I'm not going to stick with Firefox which is unfortunate because so far I love everything else about it, especially sync. I tried to download a Buffalo Bills helmet to use as an icon for a Bills fan forum which I wanted a Firefox shortcut for on my homescreen. I had to use the Android browser to do that because of this problem. Ridiculous!

    Unfortunately, Firefox for Android works quite differently than desktop Firefox in this regard. On the desktop, if you open about:config and set browser.download.useDownloadDir to false, then you prompted for the save location and file name. On Android, this simply stops Save Image from working.
    I was able to access the file by renaming Images.htm to a real file name using the ES File Explorer app. But... if you save images often, that would get old fast.
    Note: I think the name Images.htm came from the Google images results page that I was saving from, and the file name will depend on the site. When I saved from a site where the images had their own names, .jpeg was appended instead of .htm.

  • Convert jpg to gif images

    I make an application that create jpg images with jfree chart.
    But my client need the graphics in GIF format.
    I need:
    1. A conver program to pass from JPG to GIF format
    or
    2. A program to generate graphics (pie 3-d with texts) in GIF
    Someone likes help me?
    Thanks.
    MIGUEL ANGEL CARO
    [email protected]

    JFreeChart is open source, I'm sure you can get a Java GIF encoder library and wedge it into the JFreeChart API to make it create GIFs.
    Why does it need to be GIFs, though?

  • How JPG or GIF Image open in MIDP?

    How my j2me application can support jpg or gif image format. I have tested png file in midp 1.0 and its not support other than png format( im not sure about midp 2.0 does it support or not). I have seen lot of mobiles those support gif and jpg file formats. Does j2me applications on those mobile can support other image formats?
    Plus it is possible that i can develop my own decoder for jpg or gif format. I know it possible, but im talking related to its processing power consumption. Or is there any third party api exist to support jpg or gif file format on midp. Please r

    Here is the code snap that read image from a URL.. I have tested this code on localhost & two different pc on lan in emulator.. but not in actuall mobile... but i hope it will work...
    Image image = null ;
    DataInputStream httpInput = null ;
    DataOutputStream httpOutput = null ;
    HttpConnection httpCon = null ;
    String url = "http://localhost:8080/images/picture.png"
    try
    httpCon = (HttpConnection)Connector.open(url);
    int bufferSize = 512 ;
         byte byteInput[] = new byte[bufferSize] ;
         ByteArrayOutputStream imageBuffer = new ByteArrayOutputStream(1024*50);
         httpInput = new DataInputStream( httpCon.openInputStream() );
                   System.out.println("Http-Input Connecting Establish Successfully");
                   httpOutput = new DataOutputStream( httpCon.openOutputStream() );
                   System.out.println("Http-Output Establish Successfully");
    int size = 0 ;
    // read all image data ....
         while ( ( size = httpInput.read( byteInput , 0 , bufferSize ) ) != -1 )
                        imageBuffer.write( byteInput , 0 , size ) ;
    // get byte from buffer stream
              byte byteImage[] = imageBuffer.toByteArray();
                   System.out.println("read byte " + byteImage.length );
         // convert byte to image ...
         image = Image.createImage( byteImage , 0 , byteImage.length );
         return image ;
         //return null ;
    catch( IOException e )
                   System.out.println("\nUnable to Perform Image IO Operation with Host");
         return null ;
    ....................................

  • How can we put .ICO file on JButton instead of JPG or GIF etc. files

    How can we put .ICO(Icon file) file on JButton instead of JPG or GIF etc. files
    Regards
    Satinderjit

    Short answer:
    You don't. ICO files are a native windows format.
    Workarounds:
    1) Convert your files to GIF.
    2) Search for a library that can load ICO files.
    3) Write a library that can load ICO files.

  • Why won't my trial of CC Photoshop let me save my PSD images as JPG or GIF?

    Why won't my trial of CC Photoshop let me save my PSD images as JPG or GIF?

    One thing to check is that your PSD is RGB/8 or /16, but not /32  (32 bits per channel)
    If that is not the problem
    Let's try this:
    Close Adobe Photoshop if it is opened.
    Find the following:   (windows user can hit windows key + r, then in run cmd line type "%appdata%" to locate your "AppData\Roaming" directory)
    \AppData\Roaming\Adobe\Adobe Photoshop CC\Adobe Preferences CC Settings
    Rename the  "Adobe Preferences CC Settings" folder to "Adobe Preferences CC Settings_old"  so that preferences settings can be recreated.
    Reopen Photoshop CC and open a new or existing file to verify that your "save for web" option is back and not grayed out.

  • JPGs and GIFs in Coverflow not showing

    For some reason the cover view in the Finder is no longer showing previews of JPGs and GIFs, but is only showing the generic icons for each.
    Any clues as to what's causing that and how to fix it?
    Cheers.

    Try deleting the Finder.plist preference:
    /Users/Kenny/Library/Preferences/com.apple.finder.plist
    Then relaunch the Finder.
    Thanks ... Ken

  • Generate JPG or GIF Report

    Hello Members
    i want to generate a report in JPG ,GIF or any others picture type,,
    the reason is that our client need a invoice and we send the invoice by scaning
    so any body tell me how i generate the report in JPG or GIF
    i am using oracle report 6i

    Dear
    first we mail the invoice , but now they say (our client) that now mail the invoice as picture format like jpg, gif
    i don't know how to do it,, they say if oracle report convert in MS word , excel or
    others non-oracle format so why do u not mail us in picture format
    i have to do just for there requirement
    thanks for reply

  • How to convert bmp to jpg or gif??

    hi all.
    I would like to store image into database and retrieve it. But I don't know the method that can show bmp image. So I need to convert it before keep in database in type of jpg or gif?
    Can you give me any suggestion?
    or if you know how to show bmp image,tell me.
    Thank you

    Load the BMP into Microsoft Paint. Save it asJPG.
    Which version of MS Paint do you use? Because theone
    I've got only lets you save as .bmp. I'd use
    PaintShopPro.
    I'm using the version that came with my Windows 2000
    machine. But you're right, I'd forgotten that it
    didn't do that on my old Windows 98 machine.In that case ACDSee is a good tool to do this sortta conversion.

  • How can I save an object Image in a file with .jpg or .gif format?

    Greetings
    I'm programming a Ray Tracer but now I need to know like save an object Image in a file with .jpg or .gif format. Could anyone help me, please? It's very important to me do this as soon as possible. Thanks.

    In 1.4 you have ImageIO available ... javax.imageio.ImageIO.write is the method to call.
    - David

  • Java PDF to jpg or gif format

    Hi,
    If any one of them worked to convert PDF file to image format ( jpg or gif ).
    I need to convert through java code. Please let me know.

    Don't you think that asking once is enough?
    http://forum.java.sun.com/thread.jspa?threadID=608086

  • Saving file, but jpg and gif comes out garbled

    Would someone please help me? I'm at my wit's end here. I'm writing a program that reads a file and saves it, but it needs to read a maximum of 512 bytes before it starts to write. It needs to work with both text files and images.
    - It works fine with text files.
    - It works fine with bmp images.
    - It works fine with jpg and gif images under 512 bytes.
    - With a jpg or gif over 512 bytes, it comes out all garbled, but the same file size as the original.
    One thing is really confoozling me. When the image comes out garbled, I tried changing the files for both the original and the copy into text files by changing the file extension to .txt. Both the text files were identical! So if the data is identical, why is the copy not showing the same image as the original?
    import java.io.*;
         public class SaveFile{
              public static final int BUFSIZE = 512;
              public static final String LIBRARY = "C:\\";
              static int totalRead = 0;  //Total number of bytes in buffer (Max BUFSIZE).
              static int fileSize = 0;  //Size of whole file.
                  static String fileName = "";  //Name of file.
                 static char[] data = new char[BUFSIZE];  //The data in the file.
              public static void main(String[] args){
                            //Bytes already read by the buffer.
                      int charsRead = BUFSIZE; 
                          //Takes name of file from main argument.
                         for(int i=0; i < args.length; i++)
                             fileName = fileName + args;
    //Name of file including directory.
              String fetchFile = LIBRARY + fileName;
              File file1 = new File(fetchFile);
              * Reads a string from the file to data (char array).
                   BufferedReader reader =
    new BufferedReader(new FileReader(file1), BUFSIZE);
                   BufferedWriter writer =
    new BufferedWriter(new FileWriter(fileName));
                   //Will continue as long as buffer is full.
                   while (charsRead == BUFSIZE){ 
                        charsRead = reader.read(data, 0, BUFSIZE);
                        if (charsRead != -1) {
                             totalRead = charsRead;
                             write(writer);
                             fileSize = fileSize + totalRead;
                   reader.close();
                   writer.close();
              System.out.println((fileSize) + " bytes read and saved as " + fileName);
         * Writes data to a new file.
         public static void write(BufferedWriter writer) {
                   for (int j = 0; j < totalRead; j++) {
                        writer.write(data[j]);
    I stripped away the directory selection and error handling to make it simpler.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Cadvan1123 wrote:
    I think the best choice is to use a ByteArrayOutputStreamWrong. You do not need a ByteArrayOutputStream
    and I think that it uses ASCII encodingPossible, but you can't just make that assumption. On windows for instance, there's a good likelihood it could use ANSI. And BTW, ASCII is for the most part dead, as it has been superseded by UTF-8.
    Check out t [jacobs.io.DataFetcher in TUS|http://tus.svn.sourceforge.net/viewvc/tus/tjacobs/] for a threadable and optimal/close-to-optimal solution for reading in binary files.
    Edited by: tjacobs01 on Mar 20, 2010 2:56 PM

Maybe you are looking for

  • How to open saved files using 'read from text file' function

    Hi everyone, I am having a hard time trying to solve the this particular problem ( probably because I am a newb to lanbview ). Anyway , I am able to save the acquired waveforms by using the 'Write to text file' icon. I did manually modify the block d

  • Anyone has the same problem with graphics

    Lately I noticed some weird things in my screen does anyone has the same problem> Please hlp to fix it also my MBP slow when playing some movies

  • Help with "DAC Configure for Quadrature Mode.vi" in "ni5640R Frequency Translation" Example

    Hi there: I am also using the the NI PCI-5640R and I've been "studying" the program: "Frequency Translation", my intention is to modify it and produce a  closed-loop between I and O.  I am also interested in transferring what i am reading through the

  • Talk Back

    I'm using Logic 9, an apogee ensemble and a headphone amp. Is there a way to set up talk back with the built in mic on my imac? or any other ways?

  • Updating ps cs6

    Hi there! Since a couple of weeks i have a problem that the updater (for CC AND CS6) there is an update for my PS CS6 (current displayed version is 13.0.6 x64) ... try to update from updater and in app and download update. helped by some guys from su