Converting a image file (JPG or BMP or any other) to an Image object

Hello, does anyone have an idea of how I could convert a image file (JPG, BMP, GIF or any other) or even a Corel Draw (.CDR) file to a java Image object?
Thanks in advance
Wilson

Demo:
import java.awt.image.*;
import java.io.*;
import java.net.*;
import javax.imageio.*;
import javax.swing.*;
public class ImageResized {
    public static void main(String[] args) throws IOException {
        URL url = new URL("http://today.java.net/jag/bio/JagHeadshot.jpg");
        BufferedImage image = ImageIO.read(url);
        Icon icon = new ImageIcon(image);
        JLabel label = new JLabel(icon);
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(label);
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
}

Similar Messages

  • How do i convert an image object to a byte array ?

    Hi
    how do i convert an image object into a byte array
    early reply apperciated

    Oh sorry my method and the other method need to have the pixels from the Image passed to them which you get my using pixelgrabber:
    //create width and height variables from image
              int w = img.getWidth(this);
              int h = img.getHeight(this);
              //retrive picture from image
              int[] pix = new int[w * h];
              PixelGrabber pg = new PixelGrabber(img, 0, 0, w, h, pix, 0, w);
              try{ pg.grabPixels();
              } catch (InterruptedException ioe) {
                   System.err.println("Interrupted");
              if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
              System.err.println("image fetch aborted or errored");
              }

  • Converting an Image object to a BufferedImage object?

    I have a BufferedImage object, bi, which I want to resize, hence:
    Image image = bi.getScaledInstance(400, 300, Image.SCALE_DEFAULT);
    Next I want to encode the resized image to JPEG format. The problem is that inorder to use the JPEGImageEncoder.encode() method, I need to pass it a BufferedImage object. I have looked through the API and cant see a way of converting the Image object to a BufferedImage object.
    Can anyone shed some light on this problem?
    Any help will be much appreciated.

    I copied + pasted the code from:
    http://java.sun.com/docs/books/tutorial/2d/problems/ind
    x.html :-)
    So you propably could use :
    int width = 400;
    int height = 300;
    Image image = bi.getScaledInstance(width, height,
    Image.SCALE_DEFAULT);
    BufferedImage bi = new BufferedImage(width, height,
    BufferedImage.TYPE_INT_RGB);
    Graphics2D biContext = bi.createGraphics();
    biContext.drawImage(img, 0, 0, null);Greets
    PuceThis works fine; but has anybody else noticed this takes an unreasonable amount of time? How to get around this?

  • How to convert a Image object to byte Array?

    Who can tell me, how to convert Image object to byte Array?
    Example:
    public byte[] convertImage(Image img) {
    byte[] b = new byte...........
    return b;

    Hello,
    any way would suit me, I just need a way to convert Image or BufferedImage to a byte[], so that I can save them. Actually I need to save both jpg and gif files without using any 3rd party classes. Please help me out.
    thanx and best wishes

  • Converting an image object to  bufferedimage object

    Hi does anyone know how to convert an Image obj to a BufferedImage obj without casting...
    I have generated an image in an applet by rescaling a larger image but i cannot cast it to a BufferedImage as it was declared as an image type...
    thx

    Image img = setupImage(); // or however you set up your Image
    BufferedImage bimg = new BufferedImage(img.getWidth(), img.getHeight, BufferedImage.TYPE_ARGB);
    Graphics g = bimg.getGraphics();
    g.drawImage(img, 0, 0, null);

  • Made the mistake of upgrading to Lion before converting my Quicken file to QIF format.  Any suggestions??

    Made to mistake of upgrading to Lion before converting my QUicken File to QIF format needed to import into iBank or other similar apps. Any suggestions??
    Left high and dry by Apple and Intuit.

    moranpc wrote:
    Made to mistake of upgrading to Lion before converting my QUicken File to QIF format needed to import into iBank or other similar apps. Any suggestions??
    Left high and dry by Apple and Intuit.
    Your Quicken files should already be in the correct format.  Can't remember details because I converted some time ago and no longer have my old files.
    Can't understand your comment about being left "high and dry."  It's been common knowledge for six months that Lion won't support PPC applications and it's been common knowledge for several years that Intuit is abandoning the Mac.
    I will warn you that, even if you are able to convert now, the conversion does produce errors.

  • How can I export an .PLT file from Illustrator without using any other software but Illustrator

    I'm in the URGENT need of exporting a file to .PLT and no using any other software like the producer's software.

    You can't. AI doesn't produce .PLT files.

  • Converting .avi files into .mp4 .mov or any other file type for ipod

    Hello!
    I've got .avi file and i want to convert it into any playable file for my ipod is there some program? i've checked quicktime links and i ended up at a page with a 30 euro bill...
    anyways can anyone help me?

    You will find best advice over on the video forum. Most of us here are photographers.
    Click on the link below and copy and paste your question again. Good luck.
    Video questions: Click here for Premiere Elements Forum

  • How to read specific lines from a text file using external table or any other method?

    Hi,
    I have a text file with delimited data, I have to pick only odd number rows and load into a table...
    Ex:
    row1:  1,2,2,3,3,34,4,4,4,5,5,5,,,5  ( have to load only this row)
    row2:   8,9,878,78,657,575,7,5,,,7,7
    Hope this is enough..
    I am using Oracle 11.2.0 version...
    Thanks

    There are various ways to do this.  I would be inclined to use SQL*Loader.  That way you can load it from the client or the server and you can use a SQL*Loader sequence to preserve the row order in the text file.  I would load the whole row as a varray into a staging table, then use the TABLE and MOD functions to load the individual numbers from only the odd rows.  Please see the demonstration below.
    SCOTT@orcl12c> HOST TYPE text_file.csv
    1,2,2,3,3,34,4,4,4,5,5,5,,,5
    8,9,878,78,657,575,7,5,,,7,7
    101,201
    102,202
    SCOTT@orcl12c> HOST TYPE test.ctl
    LOAD DATA
    INFILE text_file.csv
    INTO TABLE staging
    FIELDS TERMINATED BY ','
    TRAILING NULLCOLS
    (whole_row VARRAY TERMINATED BY '/n' (x INTEGER EXTERNAL),
    rn SEQUENCE)
    SCOTT@orcl12c> CREATE TABLE staging
      2    (rn         NUMBER,
      3     whole_row  SYS.OdciNumberList)
      4  /
    Table created.
    SCOTT@orcl12c> HOST SQLLDR scott/tiger CONTROL=test.ctl LOG=test.log
    SQL*Loader: Release 12.1.0.1.0 - Production on Tue Aug 27 13:48:37 2013
    Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.
    Path used:      Conventional
    Commit point reached - logical record count 4
    Table STAGING:
      4 Rows successfully loaded.
    Check the log file:
      test.log
    for more information about the load.
    SCOTT@orcl12c> CREATE TABLE a_table
      2    (rn       NUMBER,
      3     data  NUMBER)
      4  /
    Table created.
    SCOTT@orcl12c> INSERT INTO a_table (rn, data)
      2  SELECT s.rn,
      3         t.COLUMN_VALUE data
      4  FROM   staging s,
      5         TABLE (s.whole_row) t
      6  WHERE  MOD (rn, 2) != 0
      7  /
    17 rows created.
    SCOTT@orcl12c> SELECT * FROM a_table
      2  /
            RN       DATA
             1          1
             1          2
             1          2
             1          3
             1          3
             1         34
             1          4
             1          4
             1          4
             1          5
             1          5
             1          5
             1
             1
             1          5
             3        101
             3        201
    17 rows selected.

  • Cannot print from file drop down menu, nor any other usual method in firefox 6.0 for win 7 home prem 64 bit

    when i try to print from your browser i click on file then choose print and nothing happens, nothing happens when i try it from file drop down and click on print preview, this is the case with Firefox 4 5 and 6! with win 7 home premium 64 bit
    it will not even let you print from the rt. click menu, that selection is not highlighted when you select a word a sentence a page or anything, and there is no print icon available in your customize the toolbar menu either, the only way I can print a page from your browser is to open internet explorer and dag the page from your browser to msie and have that browsers printer icon clicked on and it prints using m.s.i.e. 9 .
    in short there is no way to print from your browser, that I have located???????? help me

    when i try to print from your browser i click on file then choose print and nothing happens, nothing happens when i try it from file drop down and click on print preview, this is the case with Firefox 4 5 and 6! with win 7 home premium 64 bit
    it will not even let you print from the rt. click menu, that selection is not highlighted when you select a word a sentence a page or anything, and there is no print icon available in your customize the toolbar menu either, the only way I can print a page from your browser is to open internet explorer and dag the page from your browser to msie and have that browsers printer icon clicked on and it prints using m.s.i.e. 9 .
    in short there is no way to print from your browser, that I have located???????? help me

  • I foolishly removed the firefox toolbar ( meaning I have no file,view, edit, bookmark, or any other kind of tab including the search box or even a address bar). How can I get them back without reinstalling firefox please?

    Hi, I wanted more room to view on the web, so I thought I'd get rid of some of the toolbars that were taking up space. I went to the edit tab (i think) and then selected toolbars and then just unticked the ones I wanted to lose.Worked like a charm...
    Only problem was that I unticked the wrong one. Now I can't search on the web or enter a url as there is nothing there anymore. Any I do mean NOTHING expect my roboform toolbar and the "Getting Started" Firefox tab just above that.
    Reason I stressed the "nothing" is because I went on yahoo answers and someone just said...go to edit and...He obviously didn't get that I don't have any kind of firefox tabs left on my browser ( except for the "getting started" tab)
    I don't want to uninstall and reinstall as I'm worried I'll lose my bookmarked pages.
    Would be really grateful if you could advise me of an alternative solution to getting my tabs, search bar and address bar back please?
    Many thanks
    Paul
    ps as I don't have any tabs I can't tell you which version I have installed, but your clever software looks like it's got it right.

    Try this: press F10 or tap the Alt key to display the menu bar temporarily, then
    View > Toolbars > Menu Bar
    If that doesn't work, you could reset your toolbars to factory default using Firefox's Safe Mode. First, make a backup of your computer for safekeeping. To back up Firefox, see [https://support.mozilla.com/en-US/kb/Backing+up+your+information Backing up your information].
    Next, start Firefox in Firefox
    [http://support.mozilla.com/kb/Safe+Mode Safe Mode], and check only the box to reset toolbars. Be careful not to "reset" anything else if you didn't back up.
    Hope this helps.

  • Question about uploading design file when converting a html file to a master file in SP2013

    http://msdn.microsoft.com/en-us/library/jj822370%28v=office.15%29.aspx
    Here there is a note saying "When you upload your design files, you should keep all files that are related to a single design in their own folder in the Master Page Gallery. When you copy your design folder into the mapped network drive, the Master
    Page Gallery retains whatever folder structure you created."
    What do they mean keeping in own folder in Master Page Gallery?  All my design related files are in a single folder containing sub folders of images, css, js..  I copy this top folder to the http://ou.domain/_catalogs/masterpage/    
     This is also where I would copy my html file to first before converting to master file?
    Thank you.

    So I mapped to the server drive,
    http://our.domain/_catalogs/masterpage/    successfully.
     All my design related files are in a single folder containing sub folders of images, css, js..  I should copy this top folder
    to thehttp://ou.domain/_catalogs/masterpage/ 
        and also copy my html file to first before converting to master file.  My question is do I copy all these files(including the html file to be converted to master) to that masterpage folder before following the instruction to go to SP site
    setting and select and convert the html file?  Or is there any other steps I should or shouldn't do.
    Thank you.

  • Converting .bin (Binary) File to .bmp ( BMP ) File

    Hi All,
    I have a requirement to convert .bin file to .bmp file. The binary file is generated by the video frames and now i want to convert this binary file into the .bmp file. Can anybody help me how to do this and if possible then pls write the sample code.
    -Thanks

    How do you meen generated by the video frames?
    Do you mean that the .bin file is created by an application in the event of a screen shot fo example?
    If so then the big question is in what format did this application save the image data
    Please elaborate.
    Don't bank on the idea of us giving you code,
    we will if possible point you into the right direction and help where required but thats about as far as we prefer to go.

  • Convert the flat file to xml format.

    hi,
    I need to write a interface program in the R/3  to pull the flat file data from the unix application server and do some manipulation and place back into the unix application server in XML format, From the unix box XML file taken by the XI server.
    pls give me some idea to convert the flat file to XML format, through any function module or any other logic is there...
    with regards,
    Thambee.

    Hi Thambe
    in addition to the above posts
    Program to convert flat file to XML file.
    please download tool from this link:
    http://www.download.com/Stylus-Studio-2008-XML-Enterprise-Suite/3000-7241_4-10399885.html?part=dl-StylusStu&subj=dl&tag=button&cdlpid=10399885
    how to use:
    http://www.stylusstudio.com/learn_convert_to_xml.html
    http://www.sap-img.com/abap/sample-xml-source-code-for-sap.htm
    Flat file to XML
    CONVERTION OF FLAT FILE TO XML : NO OUT PUT FOUND
    Converting Idoc flat file representation to XML
    how to convert flat file into IDOC-XML
    Thanks
    sandeep sharma
    PS ; if helpful kindly reward points

  • How to convert Labview log file to text file?

    I want to open the log file in Excel or other text editor. Is there any special format of Labview log file? I thought it just binary, so I used a general program to convert binary file to Ascii file. But it failed because of the format of the log file format. Is there any other way that I can read log file in Excel? Thanks a lot.

    Dennis Knutson wrote:
    Are you refering to the front panel logging option? The actual binary format is going to depend on what controls and indicators you have on the front panel and their data types. There is an example of using the file i/o functions to read one of these files in chapter 14 of the user manual. The problem you'll have if you write a program to read a log file is that every time you add or delete a control/indicator, you'll have to rewrite your program and then you'll be unable to read older log files. You'd be better off writing your own log routines. Then you would control the binary format. There are shipping examples that you can look at for fbinary file storage.
    Yes, I am referring the front panel logging option and I will read the maual first. Thank you very much for your help.

Maybe you are looking for