How to save an image from an web page?

Hello everybody!
I have a problem and I hope someone can help me :).
I am trying to save/download an image from an web page to my computer. So given an URL which contains the image, I want to save this/write this image to disk. Here is my code:
import java.net.*;
import java.io.*;
public class Test{
    public static void main(String[] args) throws Exception{
        Test test = new Test();
        test.readFile();
    public void readFile() throws Exception{
        InputStream inputStream = new URL("http://www.google.se/images/hp1.gif").openStream();
        InputStreamReader reader = new InputStreamReader(inputStream);
        BufferedReader buffReader = new BufferedReader(reader);
        BufferedWriter bw = new BufferedWriter(new FileWriter("savedImage.gif"));
        int x=0;
        while((x = buffReader.read()) != -1) {
            bw.write(x);
        bw.flush();
}The code saves the image to disk, but unfortunately the image is distorted. Can anyone help me to solve this problem.
Thanx in advance
Best regards
/TheMan

thanx guys for your quick answers. I got i to work with the following code
InputStream inputStream = new URL("http://www.google.se/images/hp1.gif").openStream();
        FileOutputStream fos = new FileOutputStream(new File("savedImage.gif"));
        int x=0;
        while((x = inputStream.read()) != -1) {
            fos.write(x);
        fos.flush();Again, thanx guys!

Similar Messages

  • How to save an image from canvas to jpeg2000 format?

    good day! i would like some help about jj2000. i wish to save an image from canvas to a jpeg2000 format file. how will i do it using the jj2000? i just need to save it to a file.
    please help!!!
    thank you in advance!
    lrds

    I am not familiar with Jpeg2000, but the easiest way I've found to go from Java to a JPeg file is with Java Adavanced Imaging (JAI) package from Sun. Take a look at it and see if it meets your requirements.

  • How do i copy images from the web?

    How do I copy images on the web for use in a powerpoint presentation?

    Drag them to the desktop or control-click them and choose to copy them to the clipboard.
    (61484)

  • How do I add dates from a web page into iCal?

    Hello. I would love to find a way to input dates from a web page, into iCal as an event. Right now, if there is a conference or whatever that is on such and such a date, I have to keep the web page open that has the dates and time, and then open iCal, and create a new event on that date, etc. Is there a way to highlight said dates on a web page, run some automation, and voila, it is a new event in iCal?

    Don't double tap. Just try pressing on the text. That should highlight it.

  • How to save multiple images from jpeg to psd?

    I'm pretty new at this and have tons of vacation photos. Things I've read have left me terrified of leaving my images in jpeg, but I don't know how to save them all to .psd (and is that really the format I want to use?). I tried, and suddenly I'm out of space on my harddrive, so I think I've made copies of copies and have way more saved than I need. Any advice is appreciated - thanks.

    <[email protected]> wrote<br />> ...Things I've read have left me terrified of leaving my images in jpeg...<br /><br />Andrea,<br /><br />If the JPEG files are straight out of your camera, there is no harm in <br />"leaving" them as-is...  they don't degrade from just sitting there.<br /><br />The possible degradation of JPEG files comes from saving as a JPEG - <br />typically after you have done an edit to the image.<br /><br />One good way to approach the issue:  when you open an image for editing, <br />before you do anything, click the menu File > Save As...  and then choose <br />the PSD file type.  This will make a copy for you to work with, which will <br />NOT degrade as you save, re-edit, re-save, etc.  After you're finished <br />working it over, if you need a JPEG copy, use the File > Save As...  and <br />select JPEG to make an edited copy in the smaller file format.  (File > Save <br />For Web is also useful for this - it allows you to set your quality and size <br />parameters on-the-fly as you save)<br /><br />HTH,<br /><br />Byron

  • How to save a image from a document?

    Hi there
    I was trying to save the image the from the "Welcome to
    Buzzword" document but when i right clicked on it allows me to
    print the document alone. Is it possible to download the picture to
    desktop like the way we do in a Adobe PDF file?
    Karthik.

    Hello,
    Thank you for your interest in Buzzword. You can add an image
    to your Buzzword document but unfortunately you will not be able to
    save it to your desktop.
    Regards,
    Ksenija
    Acrobat.com moderator

  • How do I copy text from a web page in Safari?

    I've searched up and down and can't find the answer to this simple question.
    There is a UI element that I want to copy to the clipboard and then paste into Excel. The UI element is:
    static text of group 104 of UI element 1 of scroll area 1 of group 4 of window "Account Summary"
    The contents of this static text on the web page is "$1,000.00"
    How can I copy this to the clipboard?
    I've tried:
    select static text of group 104 of UI element 1 of scroll area 1 of group 4 of window "Account Summary"
    keystroke "c" using command down
    keystroke "l" using command down
    keystroke "v" using command down
    but it doesn't work. "Select" doesn't actually seem to select anything. However, when I run this from within Script Editor, in the Results Window I get:
    {static text "$1000.00" of group 104 of UI element 1 of scroll area 1 of group 4 of window "Account Summary" of application process "Safari" of application "System Events"}
    ... I'm confused as to what this is telling me. All I want is to copy this value to the clipboard. Any suggestions???
    Thanks,
    Jeff

    Try this:
    set the clipboard to item 1 of (get name of (static text of group 104 of UI element 1 of scroll area 1 of group 4 of window "Account Summary" of application process "Safari"))
    (10906)

  • How to make a call from a Web page

    How can I make a call from a number on a Web page ?
    If I select the number, I can only copy it ... then I cannot cut and paste into the phone dialing section ???
    I thought that by selecting the number on the Web page and holding it this would trigger the dialing ... like I used to do with my 9900 Bold BB.

    Are you holding the number or just pressing it quickly? Holding anything will produce a menu whose options would include cut & paste but just pressing the number should activate an action, in this case dialing the number.
    Try just pressing the number with a normal press and not holding it and post back with your results.  
    - If my response has helped you, please click "Options" beside my post and mark it as solved. Clicking the "thumbs up" icon near the bottom of my response would also be appreciated.

  • How do I remove content from my web page without deleting it?

    Hi,
    I previously created a webpage using iWeb on the domain name that came with dot.mac (now Mobile Me). I want to remove it from the online page without deleting it (I may want to use the content later). I've used other software at work (Morello) and there you would "archive" it. Can anyone please advise how I do it on my Mac?
    Thanks v much,
    Tony

    Tony:
    You can cause an entire page to not show in the site by using the Inspector/Page/Page pane to remove its link in the navbar. That would preserve that page until you decide to reintroduce it into the site.
    As for part of a page, the only way I could think of doing that is duplicating the page and remove the duplicate from the navbar. Then edit the original page to remove the content you want gone.
    OT

  • How to save an image from an HTTP adress

    I want to save to my HardDisk an image which adress is for
    example :
    http://www.mysite.com/img/myimage.jpg
    I cannot use CFFTP, and CFFILE does not allow HTTP adress,
    It should be something like CFFILE but on HTTP protocole ?
    Thanks for any help,
    Pierre.

    plarts wrote:
    > CFHTTP allow me to get the HTTP file and display the
    image on my screen,
    > but cannot save it on the HardDisk.
    Yes, it can. Did you look at the documentation as suggested.
    Specifically the file and path attributes?
    http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_g-h_09.html

  • How to save the image on the web through java code?

    Suppose a picture can be loaded on the browser, and nothing
    else. If I want to use a jave code to intercept the picture
    and save it into a file, what does the code look like? I know
    the URL of the picture. Thanks.

    Hi. Running your code, I got the following, with the URL as:
    String dir = "http://california.biocars.org/viewFrames2.php?";
    String fileName = "r=840190844&fn=/data/pub/kb030129_fp_2_001.img&xsize=512&ysize=512&zoom=1&contrast=2048&xcen=0.5&ycen=0.5&wval=0&jpq=100";
    String urlName = dir+fileName;
    URL imageURL = new URL(urlName);
    So something wrong? This output does not look like anything
    of a jpeg file. Thanks.
    ==================================================
    <html>
    <head>
    <TITLE> View BioCARS Data </TITLE>
    <META name='Author' content='Keith Brister'>
    <META HTTP-EQUIV="expires" CONTENT="0">
    </head>
    <body bgcolor=#ccffff>
    <form action=/viewFrames2.php method=POST><input type=hidden name=oldZoom value=1><input type=hidden name=xcen value=0.5><input type=hidden name=ycen value=0.5>
    <input type=hidden name=theTrip value=0>
    <table>
    <tr><td valign=top><table>
    <tr><td width=128 height=128><a href="/viewFrames2.php?theState=a:7:{s:4:xcen";s:3:"0.5";s:4:"ycen";s:3:"0.5";s:4:"zoom";s:1:"1";s:13:"autoZoomLevel";i:16;s:5:"azcco";i:0;s:8:"contrast";i:2048;s:6:"wvalue";i:0;&theTXYZ="><img ismap border=0 width=128 height=128 src=imageServer2.php?r=159196106&fn=/&xsize=128&ysize=128&zoom=1&contrast=2048&xcen=0.5&ycen=0.5&wval=0&jpq=100&thumbnail=1></a></td></tr><tr><td><input type=text name=seqDir value=""></td></tr><tr><td><input type=text name=fFileName value=""></td></tr></table></td>
    <td><table border=1 cellpadding=0 cellspacing=0><tr><td width=512 height=512><a href="/viewFrames2.php?theState=a:7:{s:4:"xcen";s:3:"0.5";s:4:"ycen";s:3:"0.5";s:4:"zoom";s:1:"1";s:13:"autoZoomLevel";i:16;s:5:"azcco";i:0;s:8:"contrast";i:2048;s:6:"wvalue";i:0;}&theXYZ="><img ismap border=0 width=512 height=512 src=imageServer2.php?r=159196106&fn=/&xsize=512&ysize=512&zoom=1&contrast=2048&xcen=0.5&ycen=0.5&wval=0&jpq=100></a></td><td width=8 length=512><a href="/viewFrames2.php?theState=a:7:{s:4:"xcen";s:3:"0.5";s:4:"ycen";s:3:"0.5";s:4:"zoom";s:1:"1";s:13:"autoZoomLevel";i:16;s:5:"azcco";i:0;s:8:"contrast";i:2048;s:6:"wvalue";i:0;}&bMapVal="><img ismap alt='Set Black Value' width=8 length=512 border=0 src=pixselect.php?r=159196106&bVal=2048&wVal=0&minVal=0></a></td>
    <td width=8 length=512><a href="/viewFrames2.php?theState=a:7:{s:4:"xcen";s:3:"0.5";s:4:"ycen";s:3:"0.5";s:4:"zoom";s:1:"1";s:13:"autoZoomLevel";i:16;s:5:"azcco";i:0;s:8:"contrast";i:2048;s:6:"wvalue";i:0;}&wMapVal="><img ismap alt='Set White Value' width=8 length=512 border=0 src=pixselect.php?r=159196106&bVal=2048&wVal=0&maxVal=2048></a></td><td valign=top><table><tr><td><input type=submit name=subbieResetXYZ value='Reset Zoom and Center'></td></tr><tr><td><input type=submit name=subbieZoomIn value='Zoom In'> <input type=submit name=subbieZoomOut value='Zoom Out'></td></tr><tr><td><table border=1><tr><td align=right>Auto Zoom and Center:</td><td><input onClick='this.form.submit();' type=radio name=azcco value=0 checked></td></tr>
    <tr><td align=right>Center Only:</td><td><input onClick='this.form.submit();' type=radio name=azcco value=1 ></td></tr>
    </table></td></tr>

  • Can someone please tell me how to save an image from Photoshop CS4 as a RTL file?

    I recently bought a VuTek Printer and I have to have a RTL file that is from Photoshop, does this have anything to do with PostScript?

    Are you sure about that .RTL file extension?
    All that I can find (quick search on Google), indicates that it is a Borland (software) RunTime Library file, in a TXT format.
    Are there any details in the printer's manual about what it needs, with an explanation of the .RTL format?
    Good luck,
    Hunt

  • How do you download images from a web server to your hard drive using java?

    Can anyone help me with this? The only methods that i have found that are remotely useful are getContent() andgetContentType().
    But all the code I've fouund and studied doesnt say anyone about downloading images. What do I need to be looking for to acheive this?

    You have a URLConnection to the img URL right?
    Open that connection's input stream (URLConnection.getInputStream or something like that, look it up in the Javadoc API: http://java.sun.com/j2se/1.4.2/docs/api/)
    Once you have that stream, you can read its bytes to your heart's content, and write them to a file as you wish.

  • JasperReports - how to save as PDF from Print Preview page?

    Hi all!
    How can I save reports created with JasperReperts (with iReport tool) as PDF?
    On print preview, when I select it is as PDF, and click on "save", nothing is saved. Also, I get NoClassDefFoundError despite I included all nessesry classes (did I?). Here are list of included classes
    jasperreports-1.2.7.jar;
    jasperreports-1.2.7-javaflow.jar;
    commons-beanutils-1.5.jar;
    commons-collections-2.1.jar;
    commons-logging-1.0.2.jar;
    commons-digester-1.7.jar;Here is my code:
    void printWithPreview() {
        try {
          JasperPrint print = JasperFillManager.fillReport(report, reportParam, conn);
          JasperViewer.viewReport(print, false);
          //byte[] pdfasbytes = JasperExportManager.exportReportToPdf(print); // can I use it somehow?
          JasperExportManager.exportReportToPdf(print);
        } catch (JRException e) {
          e.printStackTrace();
      }Can you help me with this?
    Also, I need to know, how to limit options "save as" only to PFD (on same Print Preview page)?
    Thank you in advance!

    Right!
    I was missing iText.jar.
    So, you need only this code to get report preview and feature to export to pdf, html and other formats:
    void printWithPreview() {
        try {
          JasperPrint print = JasperFillManager.fillReport(report, reportParam, conn);
          JasperViewer.viewReport(print, false);
          JasperExportManager.exportReportToPdf(print);
        } catch (JRException e) {
          e.printStackTrace();
      }You do not need to save it specificly to c: or other "hard coded" directory.
    Thanx 1000 times!!!

  • How can I extract information from a web page

    I wanna read some information from a webpage, and then put those information together into a table. Since I only know the url, not the file path, when I use BufferedReader(new FileReader(FilePath)), there is a FileNotFoundException. How can I do that? Thanks a lot.

    You can do it in following way....
    First you need to create the object of URL by specifying the URL name.
    URL myurl = new URL("http://www.xyz.com/index.html"); //specify your URL path here
    URLConnection conn = null;
    DataInputStream data = null;
    String line;
    StringBuffer buf = new StringBuffer();
    try {
    conn = myurl.openConnection();
    conn.connect();
    data = new DataInputStream(new BufferedInputStream(
    conn.getInputStream()));
    while ((line = data.readLine()) != null) {
    buf.append(line + "\n");
    data.close();
    catch (IOException e) {
    System.out.println("IO Error:" + e.getMessage());
    So, at the end, you have the data in your string buffer...you can use it wherever u want.
    Hope this helps

Maybe you are looking for

  • Error in Logical Port Creation

    Hi, When I try to create a logical port in my consumer system I am getting error "Error: HTTP: Error in interface for management of HTTP destinations; " Any ideas on how to fix this?

  • Aperture crashes during import from DVD

    After upgrading to ML and the latest upgrade to Aperture, I can't import photos from a DVD. DVD works with my MB.  Also Aperture has starting to quit unexpectingly.

  • Calendar and Contact Sync question

    I have been playing around with my droid 2 global for about a month now and just decided to see if I could get the contacts in my phone synced to my gmail. I have a lot of phone numbers in my phone but are not in my gmail account. The question is can

  • Find User Created the table Entry

    Hi All, This is my scenario , I've one Custom Table ztable which is there in the quality system and entries will be made in the table and it would be transported to the production system. Now My problem is this I've received one wrong entry in the ta

  • MBA Hinge

    Just curious about this. Still in the considering stage of buying an Air. I've looked at them in the Apple stores and noticed that there is a definite difference in the stiffness/rigidity of the screen hinge between the 11 and 13 inch versions. I wou