How to read a gif file into the java file?

i want to read an image(*.gif) file into my appication. can u plz help me in this?

Hi
I have made a program that display images here is the code i hope it helps
package ImageProcessing;
import java.awt.Image;
import java.awt.image.ImageObserver;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class ImageProcessing
     public static Image imRead(String imagePath)
          Image im = null;
          try
               File imageFile = new File(imagePath);
               im = ImageIO.read(imageFile);
          catch(Exception e)
               e.printStackTrace();
          return im;
     public void imWrite(Image im,String fileFormat,String imagePath) throws IOException
          File outputFile = new File(imagePath);
          ImageIO.write((RenderedImage) im, fileFormat, outputFile);
     public static void imShow(String imagePath)
          ImageObserver io = null;          
          JFrame frame = new JFrame();
          Image im = imRead(imagePath);
          ShowImage imShow = new ShowImage(im);
          frame.add(imShow);          
          frame.setVisible(true);
          frame.setTitle(imagePath);
          frame.setSize(im.getWidth(io),im.getHeight(io));
          frame.setResizable(false);
          frame.show();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     public static void main(String[] args) throws IOException
          imShow("D:\\My Computer\\Images\\Cash2.gif");          
package ImageProcessing;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Panel;
public class ShowImage extends Panel
       Image im;
       public ShowImage(Image inputIm)
         im = inputIm;
       public void paint(Graphics g)
         g.drawImage(im, 0, 0, null);
}

Similar Messages

  • How to read from and write into the same file from multiple threads?

    I need to read from and write into a same file multiple threads.
    How can we do that without any data contamination.
    Can u please provide coding for this type of task.
    Thanks in advance.

    Assuming you are using RandomAccessFile, you can use the locking functionality in the Java NIO library to lock sections of a file that you are reading/writing from each thread (or process).
    If you can't use NIO, and all your threads are in the same application, you can create your own in-process locking mechanism that each thread uses prior to accessing the file. That would take some development, and the OS already has the capability, so using NIO is the best way to go if you can use JDK 1.4 or higher.
    - K
    I need to read from and write into a same file
    multiple threads.
    How can we do that without any data contamination.
    Can u please provide coding for this type of task.
    Thanks in advance.

  • How to Combine multiple files into the one file?

    Hi all,
    How do I combine multiple canon hf10 avchd files into the one file with a new extension. No need to be compressed.
    Afterwards, I also want to split this combined file to original files.
    Need Help!

    Yes, angelanna. You can merge or split your video file via FCP sequence.
    ahaah, maybe I think angelanna would like to get the resulting file with MTS format because he mentioned “No need to be compressed”. Are you asking for this, angelanna?
    If so, a simple MTS files managing and editing tool  is needed. Maybe you can have a try the Mac version of Aunsoft Final Mate for managing HD camcorder footages. I just downloaded its free trial version and it offers a simple way of garping footages directly  from camcorder. And also it provides a attractive feature to join flawlessly and split accurately native MTS files for video file output with original MTS format.
    Maybe this is the tool cwhich an help you out, angelanna.
    Enjoy your video.

  • How do you convert a jar file into a java file,  ?

    how do you convert a jar file into a java file ?
    I am new to Java ,but have a little experience in C++ and Visual Basic.
    I want to edit and maybe create my own mobile games that are written or converted into jar files.
    At the moment I am using Java NetBeans , and Easy Java( the java pad).
    However the only solution I tried was to open the JAR file in winrar and see that its made up of png picture files,
    midi music files and class files. Unfortunately when I uncompressed the JAR file , there was NO java file to be seen and the JAVA editors Do not show the class file like a Java file. So why is there no extension Java file in the mobile JAR game ?

    801283 wrote:
    how do you convert a jar file into a java file ?You generally don't. There exist decompilers, but if you're meant to have the source, you should either have it because you are the author, or you should be able to get it from the author.
    I am new to Java ,but have a little experience in C++ and Visual Basic.Does that experience include turning .exe files into C++ code? Because that's the equivalent of what you're asking
    I want to edit and maybe create my own mobile games that are written or converted into jar files.Eh?
    Are you saying you want to take existing games and modify them? If the creators allow you to modify their source, then they'll provide you with that source (the .java files). If you're allowed to add things but not modify, you don't need .java files. Just documentation, which, again, the creators should be providing.
    Or are you saying you want to create your own games and distribute them in jar files? If so, there's no need to turn jars into .java.
    However the only solution I tried was to open the JAR file in winrar and see that its made up of png picture files,
    midi music files and class files. Unfortunately when I uncompressed the JAR file , there was NO java file to be seen and the JAVA editors Do not show the class file like a Java file. So why is there no extension Java file in the mobile JAR game ?Why would you expect there to be one?

  • Do i have to pack all files into the war file/

    Hi,
    suppose a file (say bb.html, for example) within a war has a link to a document outside the war, say c:\aa.doc for example, after deploying the war into the j2ee application server, the linked file cant be found, simply because the file(aa.doc) isn't packed with bb.html. I am wondering if there is a way that I can establish the link, even they are placed in different location.
    to exend the question, in my understanding, the web container within the j2ee application server is a Tomcat run evironment, do I need to connection the applicaiton server to one of web servers like appache web server, IIS etc to get better preform? if yes, how?
    Can anyone give some explanation please?
    Thank you very much!
    Ken

    No they do not have to be packed into the same War file.
    The application server does have to know where they are so that it can handle requests for a given "html" file.
    For example: "bb.html" was found in the war file you deployed.
    it links to "aa.doc" - where is the directory or war file that contains "aa.doc"?
    It too needs to be "deployed" within the server in order to be found.
    I hope this helps.

  • FireFox will not start due to message indicating that ssl3.dll is missing and indeed it is not in the program files. But I can not seem to be able to reinstall Firefox or to copy the ssl3.dll file into the program files. Help?

    Webroot identified ssl3.dll as a threat and deleted it. Now I can not start Firefox, nor can I copy ssl3.dll into the Firefox Program file. I tried uninstalling Firefox and reinstalling it, but it always shows as an upgrade and does not seem to add ssl3.dll. HELP?

    1. Open Webroot
    2. Click on PC Security
    3. Click on the Quarantine tab
    4. Select ssl3.dd
    5. Click restore

  • How to read/know/use  relative paths in java files ?

    I am able to access files in java after using the
    String TxtURL = "file:///c:/files/TEXTS/";and then loop
    = new File(ma.TxtURL +filename );However , I need to use this in several drives , C , D E etc , how can I use relative path ?
    I used these but they didn't work
    String TxtURL = "file:///TEXTS/";
    String TxtURL = "file:////TEXTS/";
    String TxtURL = "file:///./TEXTS/";
    String TxtURL = "file:///../TEXTS/";

    ya batch , I want to run a java program from batch file
    java C:\...\fileand as u know that C will change , so any suggestions/solutions ?
    thanks

  • .class file into the .exe file - simplest possiblity ???

    Dear All,
    I have a java program....and the compiled ".class" file for this....basically, it is a Frame..i will run this said program from my command prompt like,
    C:\java megalaunch
    ...the frame will appear now....
    what i want to know is .............Is it possible to change this said class file, in to an .exe file...so that, (instead of going for a command prompt for running the said program) i can just double click the said .exe file and start that said Frame....
    pl. post a reply,
    Sakthivel S.
    P.S: I dont want to use the batch file option for the above...

    Easier (and more reliable, smaller. etc) than creating an executable .exe file is to create a Windows (desktop) shortcut to the GUI program, or create an executable .jar that packages your GUI. Both are executable/clickable solutions.
    Use a desktop shortcut or an executable jar file:
    http://developer.java.sun.com/developer/qow/archive/21/index.html

  • How can  I include my database file into my jar file?

    Hi,
    I am doing several tests for the jar command....
    I tried to put the database file into my jar file, but when the program run, it just couldn't find the database file, so how may I include the database file into the jar file? Not only that, it also can't find the policy file etc.

    sorry, I think I found the solution, I should have had read the API more carefully.

  • Embed an external PDF file into the XML

    Dear All,
    We have a program which creates the XML file on the Application server when we execute it.
    My requirement is to Embed an external PDF file into the XML file while generating it through
    program from SAP.
    Please let me know how this is possible.
    Thanks & Regards,
    Vinit

    Yes, you can do it. You have to use an absolute path and add it not only to the folder but to the .manifest
    I wrote a blog post explaining how to do it:
    http://www.captivatecrazy.blogspot.com/#!http://captivatecrazy.blogspot.com/2012/03/embed- pdf-in-captivate-for-lms.html

  • Inputting an excel file to the java servlet program

    Hi,
    How can I input an excel file into the java servlet program? I am using POI HSSF programming to read the content of that excel file.I have created a form that will accept the path from the user and in the servlet program, I have called a post method to retrieve the path of the file. I am getting the path of the file as a string.Then I have to access the file to read the data. But it is not working. What should I do?.Please help me.
    I have created an html file to create a form that will ask the path of the file to be loaded into the servlet program.Please give me a solution,thanks in advance. The servlet program that receives the file is shown below. It just only take the name of the file and prints if that is ok.
    <html>
    <body bgcolor="green">
    <center>
    <form method="post"  action="http://localhost:8080/examples/servlet/Ron1">
    <table>
    <tr>
    <td><B>ENTER THE PATH OF THE FILE</td>
    <td><input type=file name="path"></td>
    </tr>
    </table>
    <input type=submit value= "submit" >
    </form>
    </body>
    </html>
    import java.io.*;
    import javax.servlet.*;
    import java.lang.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import java.text.*;
    import java.util.*;
    import com.oreilly.servlet.MultipartRequest;
    import org.apache.poi.hssf.usermodel.*;
    public class Ron1 extends HttpServlet
       public void doPost(HttpServletRequest request, HttpServletResponse response)   throws IOException, ServletException
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            String u = request.getParameter("FileToUpload");
            out.println("The Path is "+u);
            System.out.println("The path is "+u);
            MultipartRequest multi = new MultipartRequest(request,u,10 * 1024 * 1024);
            System.out.println("path is "+u);
            Enumeration files = multi.getFileNames();
            File fUploadedFile = null;
            String sFileName = "";
            out.println("path is "+u);
            while(files.hasMoreElements())
                            String name = (String)files.nextElement();
                            out.println("file is "+name);
                            sFileName = multi.getFilesystemName(name);
                            String type = multi.getContentType(name);
                            fUploadedFile = multi.getFile(name);
                    FileInputStream fis= new FileInputStream(fUploadedFile);
                   HSSFWorkbook wb=new HSSFWorkbook(fis);
                    System.out.println("The path is "+u);
                    out.println("File has identified successfully\n");
                    out.close();
       }

    Hi,
    Can you try to use classes from java.net package (URL, URLConnection) to pass the contents of excel file to servlet?
    HTH
    Vishal

  • How do I read the images I bundled into the jar file?

    I just wrote an applet that uses
         Toolkit tk = Toolkit.getDefaultToolkit();
         tk.getImage("blah.gif");to load a bunch of image files. The class file and gif images were bundled into a jar file to minimize the number of connections the browser has to make to the server.
    The applet works fine in appletviewer but trips a java.security.AccessControlException: access denied (java.io.FilePermission select.gif read) when run in a browser. I know you normally use Applet.getImage(URL) to load images but wont that circumvent the JAR file and make a seperate connection to the server for each image? That would defeat the purpose of using a JAR file.
    How do I access the image files I bundled into the JAR file?

    From your Applet class, write the following:
    URL imgUrl = getClass().getResource("blah.gif");
    Image img = getImage(imgUrl);The returned URL will be from the Applet class ClassLoader, which will look into the specified archive (jar) file.

  • HT2518 How do I transfer music from an external hard drive to my itunes on my mac? I have put the files into the itunes media, but they are not showing up in iTunes!

    How do I transfer music from an external hard drive to my itunes on my mac? I have put the files into the itunes media, but they are not showing up in iTunes!

    Hi, did you try iTunes>File>Import?

  • How can I convert my Open Source document files into Word document files? I cannot download Pages since my Macbook Air does not have the most recent software.

    How can I convert my Open Source document files into Word document files? I cannot download Pages since my Macbook Air does not have the most recent software. I downloaded open office to my mac to try and save money. It worked well for a while. Now I get this pop-up message that asks me to "Reopen" and when I select the option, nothing happens. I cannot save my documents anymore and I cannot convert them to word. Help!

    dwb wrote:
    Does OpenOffice output Word documents by default or do you have to select it manually?
    You have 17 options to save as in Open Office, one of which is .doc  files,  yes it needs to be saved manually.
    You may be able to default to DOC, but have not tried same.
    Since Open Office is 99% same as Word, I use it, or Word, either one.  Open Office is a bit less buggy than Word 11'

  • After creating a new user account, how do I move my files into the new user?

    I have an issue where my 'Desktop/Screensaver' prefs seem to be corrupt somehow. When I click on that icon in System Preferences, it stalls and I get the spinning ball, thus resulting in a force quit. After reading a Mac Format magazine where someone wrote in with a similar issue, they said to trash various prefs (did that and made no difference) and if that didn't work, try creating a New User account (therefore creating brand new system prefs) and move your stuff over.
    Well, I've created the New User account, but I can't figure out how to move/copy my stuff into the user folders. After copying and attempting to move stuff in, I see folders with a red circle with a white line through it (like a 'no entry' sign).
    Any clue as to how this can be done? All I'm trying to do is to reinstate the system prefs so they are not corrupt anymore on my log-in.

    No. Not the main Library folder. Make absolutely sure you are in the Home Library folder and not the main Library folder.
    Your Home Library folder is hidden in Lion. To get to it, in the Finder menu, select GO and hold the option key down. Select Library in the submenu. The Finder window will open in your Home Library. This is where your user prefs are stored.
    Once there, you will see the Preferences folder. Open it up, select all items within it and move them to the trash. You will need to restart in order for the new Finder preferences to be recreated.
    Once you restart, then you will be back to the default preferences to the system and all applications. And yes, it will affect all settings including your Dock, just as logging into a new user. You will have to reset everything there also.
    If you wish to do a selective method, instead of deleting all preferences, try deleting the one associated with your problem. Screen saver problems should be affected by the system preferences, so try deleting this:
    com.apple.systempreferences.plist
    com.apple.systempreferences.plist.lockfile
    Note that when you delete system file preferences, a restart will be required. For applications, just quit the application before trashing preference files.

Maybe you are looking for

  • How can I display & split the audio & video from the same digitized clip?

    I digitized a scene into iMovie that I edited on a professional system which I don't have access to anymore. The whole scene is 1 clip. Now I see a few tweaks that I want to make, so I was hoping to do them in iMovie. I want to "pull up" the audio in

  • RDDEXCEL job is getting cancelled

    Dear All, While transporting the request, the request ending with error code -12 , when i checked the log its showing RDDEXCEL JOB is cancelled , This is happening for every request . Thanks in advance . Thanks S SURESH <subject_modified> Do NOT use

  • Fault policies not getting executed for called BPEL process

    Hi, I am facing one issue in execution of fault policy for a called BPEL Process. I have two BPEL Processes - BPELProcess1 and BPELProcess2. We have fault-policies and fault-bindings file. Case1 - BPELProcess2 is synchronous :- BPELProcess2 throws a

  • Smsy "Read System Number" customer number unknown for installation

    Hi gurus, I 'm configuring SMSY and following the steps outlined in the IMG in the basic settings and trying to configure RFC connections to/from satellite systems. In SMSY, I have 2 systems configured SMA and BIF. tcode SMSY-> Systems -> SAP ERP ->

  • Dimension - Line Item

    Hi Everybody, when does make sense to define a Dimension as a Line Item? what are the pros and cons? Thanks FedeX