×

Discussion Board

Results 1 to 15 of 15
  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    8

    How to download multiple images from a website

    Hello all, been watching this forum but decided to join now. i am having a hard time downloading and displaying multiple images from a website. i know i am not quite off the mark and i am suppose to create an array of images to hold the images, in other to draw them on a canvas, but i can't seem to figure it out(or how to initialize it correctly). please kindly be of assistance with any helps or links. i was following a tutorial and was trying to implement it on my own, but the tutorial was only downloading and viewing a single image, so it kind of different to what i need.

    here is the code:

    Code:
    public class ImageView extends MIDlet implements CommandListener {
       private Display display;
       private Form form, form2;
       private Command view;
    
        public ImageView(){
            form = new Form("pics");
            form2 = new Form("");
            view = new Command("View", Command.SCREEN, 2);
            form.addCommand(view);
            form.setCommandListener(this);
            
        }
        
        public void startApp() {
            display = Display.getDisplay(this);
            display.setCurrent(form);
        }
    
        public void pauseApp() {
        }
    
        public void destroyApp(boolean unconditional) {
        }
    
        public void commandAction(Command c, Displayable d) {
            if(c == view){
                HttpConnection conn = null;
                InputStream is = null;
                StringBuffer sb = new StringBuffer();
               
    
                try {
                    conn = (HttpConnection)Connector.open("http://www.dreamstime.com/free-images_pg1");
                    is = conn.openInputStream();
                    
                    byte imageData[] = null;
                    int len = (int)conn.getLength();
                    if (len != -1)
            {
            imageData = new byte[len];
           
     Image[] img = new Image[imageData];  //trying to initialize it but not sure if its correct
       
     // Read the png into an array
                    is.read(imageData);
            }
                    int ch;
                 while ((ch = is.read()) != -1) {
                     sb.append((char)ch);
                    im = Image.createImage(imageData, 0, imageData.length);
                 }
    
    
                }catch(IOException e){
                    e.getMessage();
                }
    
            }
            form2.append(im);// not working
            display.setCurrent(form2); // not working
        }
    }
    please kindly give me guidelines (or links to download multiple images).. thank you

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: How to download multiple images from a website

    Welcome to the Forum Nokia Discussion Boards..

    you have to download the images, but in this there are some points,
    Do you wanna download all the images first and then draw..?
    Or do you wanna keep on download the images and the image which was just downloaded juts draw that?
    You have to make the requirement much more clear..
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    8

    Re: How to download multiple images from a website

    Hello. thanks for the response. sorry for not being clear

    yes, i want to download all the images first before i draw them. because i think the second method you asked might take too much resources.(am not sure, but the first method is what i had in mind.

    what i want to do in more detail:

    1. download all the images from the website
    2. filter them so i only the display images with the same height and width(only those in the thumbnails)
    3. display them on a canvas.( but for test purpose, am just using a form now)

    hope am clearer now. thanks
    Last edited by sparrow007; 2010-05-13 at 11:42.

  4. #4
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: How to download multiple images from a website

    Quote Originally Posted by sparrow007 View Post
    tutorial was only downloading and viewing a single image, so it kind of different to what i need.

    here is the code:

    Code:
        public void commandAction(Command c, Displayable d) {
            if(c == view){
                HttpConnection conn = null;
                InputStream is = null;
                StringBuffer sb = new StringBuffer();
               
    
                try {
                    conn = (HttpConnection)Connector.open("http://www.dreamstime.com/free-images_pg1");
                    is = conn.openInputStream();
                    
                    byte imageData[] = null;
                    int len = (int)conn.getLength();
                    if (len != -1)
            {
            imageData = new byte[len];
           
     Image[] img = new Image[imageData];  //trying to initialize it but not sure if its correct
       
     // Read the png into an array
                    is.read(imageData);
            }
                    int ch;
                 while ((ch = is.read()) != -1) {
                     sb.append((char)ch);
                    im = Image.createImage(imageData, 0, imageData.length);
                 }
    
    
                }catch(IOException e){
                    e.getMessage();
                }
    
            }
            form2.append(im);// not working
            display.setCurrent(form2); // not working
        }
    }
    As you said that you are able to download the single image and you are also able to render the same.
    Now what you have to do is repeat the process of downloading the images(bold|italic|Blue lines) until you get the last image and then you can draw the same to which you want to.For this you have to have the multiple URL's against the every image.

    I would like to recommend that you should hit the URL for the images information like,
    1. How many images are there/
    2. What are the image size
    3. At what time you will be getting the last image etc..

    So when you hit the URL for the Images details you can get all the required details in the XML with the URL of the images and other details.You then parse the XML and fetch the information.Hit the server with the URL from the XML as many times and get the image one by one.

    Now since you have the details that when about you are near to getting the last image and then you can stop the downloading and can start the rendering.

    Please check this is just a solution to the issue to fix,you can even think better than this.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    8

    Re: How to download multiple images from a website

    Quote Originally Posted by raj_J2ME View Post
    As you said that you are able to download the single image and you are also able to render the same.
    Now what you have to do is repeat the process of downloading the images(bold|italic|Blue lines) until you get the last image and then you can draw the same to which you want to.For this you have to have the multiple URL's against the every image.

    I would like to recommend that you should hit the URL for the images information like,
    1. How many images are there/
    2. What are the image size
    3. At what time you will be getting the last image etc..

    So when you hit the URL for the Images details you can get all the required details in the XML with the URL of the images and other details.You then parse the XML and fetch the information.Hit the server with the URL from the XML as many times and get the image one by one.

    Now since you have the details that when about you are near to getting the last image and then you can stop the downloading and can start the rendering.

    Please check this is just a solution to the issue to fix,you can even think better than this.

    the url is just a page with the images in thumbnails. i wanted to get those thumbnail images on the page instead of going to the image specific page. I thought i could read the whole page first before i process for images. But from the your recommendation, are you suggesting that i use an xml parser. ( never done it before, don't know much about xml) any links on where i can get an example of xml parser that fits my requirement?

    does that also mean i don't need the arrays?

    am really sorry for the bother.

    by the way, am not able to achieve it from the example, it keeps giving me an IllegalArgumentException.

  6. #6
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: How to download multiple images from a website

    Quote Originally Posted by sparrow007 View Post

    1.the url is just a page with the images in thumbnails. i wanted to get those thumbnail images on the page instead of going to the image specific page. I thought i could read the whole page first before i process for images.

    2.But from the your recommendation, are you suggesting that i use an xml parser. ( never done it before, don't know much about xml) any links on where i can get an example of xml parser that fits my requirement?

    3.does that also mean i don't need the arrays?


    4.it keeps giving me an IllegalArgumentException.
    Well let move point wise...

    1. Your idea is also great one and you can follow that..
    How did you know that how many images are there?
    How did you identify the every images and create the real image?
    Or are you able to do all the above two points?

    2.If you will follow the recommendation then yes..

    3.Well Yes and No, you can use, or you can do without this?

    4.The occurrence of exception is a different story, you should convert that byte array to the int array and then use the Image.createRGBImage(); in order to create the images.

    Please check that whether these lines can help you..
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    8

    Re: How to download multiple images from a website

    Quote Originally Posted by raj_J2ME View Post
    Well let move point wise...

    1. Your idea is also great one and you can follow that..
    How did you know that how many images are there?
    How did you identify the every images and create the real image?
    Or are you able to do all the above two points?

    2.If you will follow the recommendation then yes..

    3.Well Yes and No, you can use, or you can do without this?

    4.The occurrence of exception is a different story, you should convert that byte array to the int array and then use the Image.createRGBImage(); in order to create the images.

    Please check that whether these lines can help you..
    thanks for your feedback and guidelines.
    from your first question1: no i have no idea on how to do the two questions asked or how to determine how many images are there as the url can change, thats why i tried to get an array big enough.
    Image [] img = new Image[]; // but don't know what to initialize it with so that its big enough not to get an ArrayOutofBoundsException and i can't use the content lenght.

    2. i know there is Kxml for j2me, is it the same thing as xml?.

    will try what you recommended and give you feed back. thanks once again
    Last edited by sparrow007; 2010-05-13 at 13:02.

  8. #8
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: How to download multiple images from a website

    But you have to clear about the issues that can arise in the development..
    What I would say it is hardly matter that how you have download the images.
    Thats why I recommend you that solution of the XML so that at the starting time only you can have the idea about all the things that is gonna happen in your app.

    If you have the idea of all the things that are gonna happen, what all you need to do?
    Then you can rather easily handle the things..
    How this sounds to you?
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  9. #9
    Registered User
    Join Date
    May 2010
    Posts
    8

    Re: How to download multiple images from a website

    Quote Originally Posted by raj_J2ME View Post
    But you have to clear about the issues that can arise in the development..
    What I would say it is hardly matter that how you have download the images.
    Thats why I recommend you that solution of the XML so that at the starting time only you can have the idea about all the things that is gonna happen in your app.

    If you have the idea of all the things that are gonna happen, what all you need to do?
    Then you can rather easily handle the things..
    How this sounds to you?
    yeah what you are saying is correct and makes a lot of sense. i have not built too many applications, so i am still in the learning curve when it comes to trying to figure out issues that arise during development. but as you recommended, i am looking into using XML as a means.

  10. #10
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: How to download multiple images from a website

    Quote Originally Posted by sparrow007 View Post
    yeah what you are saying is correct and makes a lot of sense. i have not built too many applications, so i am still in the learning curve when it comes to trying to figure out issues that arise during development. but as you recommended, i am looking into using XML as a means.
    Yeah, you make your XML file as per your convenient and add the tags that can contains all the information in the apppropreate tags.Fetch the same at the time of the launching of the app and parse the XML.Use the information in the app. I guess this should fulfill the need.

    If any concern then please write here,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  11. #11
    Registered User
    Join Date
    May 2010
    Posts
    8

    Red face Re: How to download multiple images from a website

    Quote Originally Posted by raj_J2ME View Post
    Yeah, you make your XML file as per your convenient and add the tags that can contains all the information in the apppropreate tags.Fetch the same at the time of the launching of the app and parse the XML.Use the information in the app. I guess this should fulfill the need.

    If any concern then please write here,
    am not really sure what you meant by making my XML file to my convenience, because i thought i was suppose to parse an already existing XML document(which is the website) or do you mean i create my own XML document that parses the website for the images and then use my app to connect the XML i created?. is that possible?

    another question i have is that, i read XML parsing are done on a separate thread so i was wondering if i can use the same thread used by the XML parser for displaying the images on the canvas or is it best i should have a seperate thread for the Canvas.


    thanks. I hope i made a lot of sense.

  12. #12
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: How to download multiple images from a website

    Quote Originally Posted by sparrow007 View Post
    1. am not really sure what you meant by making my XML file to my convenience,

    2. another question i have is that, i read XML parsing are done on a separate thread so i was wondering if i can use the same thread used by the XML parser for displaying the images on the canvas or is it best i should have a seperate thread for the Canvas.

    1. I mean is that the XML will of course be created by the server side team, but you can let them to create the XML as per your convenience for the understanding and parsing both.You decide the Tags flow and the position of the child and parent nodes.

    Then the server side guy will upload the XML against the URL and you when will hit the URL, fetch the XML and parse the same in order to process the data.

    2.Yeah it will be better if you could that.You make a different class for handling the XML and which contains it's own thread.Just do that..
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  13. #13
    Registered User
    Join Date
    May 2010
    Posts
    8

    Re: How to download multiple images from a website

    Quote Originally Posted by raj_J2ME View Post
    1. I mean is that the XML will of course be created by the server side team, but you can let them to create the XML as per your convenience for the understanding and parsing both.You decide the Tags flow and the position of the child and parent nodes.

    Then the server side guy will upload the XML against the URL and you when will hit the URL, fetch the XML and parse the same in order to process the data.

    2.Yeah it will be better if you could that.You make a different class for handling the XML and which contains it's own thread.Just do that..
    am sorry, i don't know if i have misled you a bit..am not affiliated to the website in anyway, so i have no access to their server.its just an independent project i am doing. I just wanted to clear that up, in case you were thinking otherwise. Sorry for all the inconvenience. i don't know if your current suggestion still holds.. but i have learnt a lot from it. A friend suggested that it will be more difficult or if not nearly impossible as an independent project, to implement the application without being affiliated with the server side. what do you think about this?..
    Last edited by sparrow007; 2010-05-18 at 19:59.

  14. #14
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: How to download multiple images from a website

    Quote Originally Posted by sparrow007 View Post
    A friend suggested that it will be more difficult or if not nearly impossible as an independent project, to implement the application without being affiliated with the server side. what do you think about this?..
    True indeed...
    I am recommending to you that you should have affiliated with the server side, However if this is company's project then they should have been hired/acquired a guy who will handle the server side coding and can read and write the responses to the client.So just talk to your manager and he/she will surely understand this as the MUST requirement.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  15. #15
    Registered User
    Join Date
    May 2010
    Posts
    8

    Re: How to download multiple images from a website

    Thanks, you have been a great help!

Similar Threads

  1. Help with creating Images..Pls
    By rj_cybersilver in forum Mobile Java Media (Graphics & Sounds)
    Replies: 0
    Last Post: 2005-03-02, 01:58
  2. Problem with PNG Images
    By cyphre666 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 4
    Last Post: 2003-12-12, 18:20
  3. how to extract multiple images from Single Image File
    By memphis_ in forum Mobile Java General
    Replies: 2
    Last Post: 1970-01-01, 02:00

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×