Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Url Image stream? Getting an Image url.

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Url Image stream? Getting an Image url.

    I have this code, and inside the 'saveImage()' function i explain in comments what my problem is. this code is meant to go to an image url and save that image to my desktop.

    the main dilemma is I can't go directly to an image url (such as website.com/image.jpg)
    I can get to a webpage that has multiple images on it, but need to single out a specific one.

    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.net.URL;
     
    public class main {
    	public static void main(String[] args) throws Exception {
     
     
    			String numString = "WarCraft_";
     
    			String imageUrl = "http://sonsofthestorm.com/viewer.php?artist=raneman&cat=warcraft&art=1";
    			String destinationFile = "C:\\Users\\Turtle\\Desktop\\image.jpg";
     
    			saveImage(imageUrl, destinationFile);
     
     
    	}//end main
     
     
     
    		public static void saveImage(String imageUrl, String destinationFile) throws IOException {
    			// somewhere around here, i need the program to look at this website url, (imageUrl)
    			//  find any images that start with the words: "WarCraft_" (numString)
    			 // and get that image, or set imageUrl to that image's url.			 
     
    			URL url = new URL(imageUrl);
    			InputStream is = url.openStream();
    			OutputStream os = new FileOutputStream(destinationFile);
     
    			byte[] b = new byte[2048];
    			int length;
     
    			while ((length = is.read(b)) != -1) {
    				os.write(b, 0, length);
    			}
     
    			is.close();
    			os.close();
     
    		}
     
     
    }//end class
    Last edited by turtlemaster; June 30th, 2012 at 09:38 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Url Image stream? Getting an Image url.

    need to single out a specific one.
    Are you saying that there is an html page that loads some images and you want to scan the text of that html page and find the tag that points to one image so you can use that URL to read and save that image?
    Or is your problem with the reading and saving an image when you have the URL to that image?

    Please Edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Url Image stream? Getting an Image url.

    I thought I pressed reply but I dont see it. So hopefully there won't be a double post >_>
    but its the first thing you mentioned that is my problem.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Url Image stream? Getting an Image url.

    Html pages can be very complicated when they use javascript to build what is displayed in the browser. Have you tried reading the html for the page you want to scan and printed it out to see what is in it? That could help you decide how to scan the page's contents for the URLs.

    There are html parsing packages that could help you.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Image Doesn't Display with Qualified Image Path????
    By swaginator in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 31st, 2012, 12:29 AM
  2. Create image Jpeg from an object of Image class.
    By Ramandeep in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: December 31st, 2011, 11:34 PM
  3. Web app image processing from stream to UIComponent
    By throwcode in forum File I/O & Other I/O Streams
    Replies: 8
    Last Post: August 19th, 2011, 10:58 AM
  4. Replies: 2
    Last Post: February 14th, 2011, 05:36 PM
  5. Pixel Alteration in an image/image rotation
    By bguy in forum Java Theory & Questions
    Replies: 3
    Last Post: November 1st, 2009, 10:50 AM