Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Trusted Contributor
Posts: 204
Registered: ‎07-14-2010
My Device: 8100
My Carrier: Blackberry developer
Accepted Solution

Is it possible to read and display multiple images?

hi all ,

 

   Am using dom parser,which parses the Thumbnailimage of rss feed

 

<ThumbnailImage>Images/51-ABP-1-vpf.gif</ThumbnailImage>

 

 

there are multiple tags of this kind in this rss which contains different images

 

 

is it possible to parse all the images and display as a list ?

Developer
Posts: 468
Registered: ‎08-07-2009
My Device: Curve, Bold, Storm
My Carrier: Blackberry Developer

Re: Is it possible to read and display multiple images?

Hi,

 

First of all you need to make the socket connection.

 

Then you will get the images/data in bytes.

 

Then you need to convert that data in to bitmaps and need to display in Grid.

 

 

Tell me the status where have you reached yet.

 

Thanks

Ekansh

----------------------------------------------------------
feel free to press the kudos button on the left side to thank the user that helped you.
please mark posts as solved if you found a solution.
Trusted Contributor
Posts: 204
Registered: ‎07-14-2010
My Device: 8100
My Carrier: Blackberry developer

Re: Is it possible to read and display multiple images?

[ Edited ]

I have done till this  ,

private class Connection extends Thread
	{ 
	    public Connection()
	    { 
	       super(); 
	    } 
	    
	    public void run() {  
	    	Document doc;  
	    	StreamConnection conn = null; 
	    	InputStream is = null;  
	    	
	    	try {     
	    		String url ="http://www.test.com/api/search/ ";
	    		conn = (StreamConnection) Connector.open (url +";deviceside=true"); 
	    		DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); 
	    		docBuilderFactory.setIgnoringElementContentWhitespace(true);
	    		docBuilderFactory.setCoalescing(true);
	    		DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();    
	    		docBuilder.isValidating();      
	    		is = conn.openInputStream();    
	    		doc = docBuilder.parse(is);     
	    		doc.getDocumentElement().normalize();  
	    		docBuilderFactory.setIgnoringElementContentWhitespace(true);
	    		docBuilderFactory.setCoalescing(true);
	  	    		NodeList list = doc.getElementsByTagName("ThumbnailImage");
	  	    		    for (int i = 0; i < list.getLength(); i++) {    
	    			Node textNode = list.item(i).getFirstChild();  
	    		  nodeValue =  "http://www.test.com/"+ textNode.getNodeValue();
	    		  listElements.addElement(nodeValue);
	    		 
	    			}    } catch (Exception e) {   
	    				System.out.println(e.toString());    
	    				} finally {   
	    					if (is != null) {  
	    					try { is.close(); 
	    					} catch (IOException ignored) {}   
	    					}        if (conn != null) {  
	    						try { conn.close(); } 
	    						catch (IOException ignored) {} 
	    						}    }   
	    				Application.getApplication().invokeLater(new Runnable() { 
							public void run() {         
							_list.setSize(listElements.size()); 
							invalidate();
							}   
							});
	    						}

	
  
	}

 

Trusted Contributor
Posts: 204
Registered: ‎07-14-2010
My Device: 8100
My Carrier: Blackberry developer

Re: Is it possible to read and display multiple images?

can anyone tell how to proceed with this to get the image displayed as list ?

i saw abt encoding the data for an image to display in other forums , but here am parsing the <image> tag from rss.. hw could this be encoded ?

 

 

any solution ?

Developer
Posts: 468
Registered: ‎08-07-2009
My Device: Curve, Bold, Storm
My Carrier: Blackberry Developer

Re: Is it possible to read and display multiple images?

hi,

 

 

in.read(data,0,data.length);
image = EncodedImage.createEncodedImage(data, 0, data.length);

Hi u need to get the data in bytes and create an image.

and you need to use it..

 

image = Utility.ScaleImageToSize( image, width ,height );

----------------------------------------------------------
feel free to press the kudos button on the left side to thank the user that helped you.
please mark posts as solved if you found a solution.
Trusted Contributor
Posts: 204
Registered: ‎07-14-2010
My Device: 8100
My Carrier: Blackberry developer

Re: Is it possible to read and display multiple images?

could yu please mention in which part of my coding i should implement the one yu gave?

Developer
Posts: 70
Registered: ‎01-02-2009
My Device: Not Specified

Re: Is it possible to read and display multiple images?

 

I guess, you are only parsing the XML and getting the URL of the image in a list.

 

From that(listElements) you have to download the image, after that yu can use Ekansh's code.

---------------------
Best Regards,
Kannabiran.
---------------------
Don't forget to mark your post as solved if you got answer. And give kudos.
Trusted Contributor
Posts: 204
Registered: ‎07-14-2010
My Device: 8100
My Carrier: Blackberry developer

Re: Is it possible to read and display multiple images?

yes yu are right .. my full url of the image path is contained in

nodeValue of the line

 

nodeValue = "http://www.test.com/"+ textNode.getNodeValue();

listElements.addElement(nodeValue);

 

 

 

now the full path of each image is in nodeValue

from this how can i download each images ?

any sample codes?

 

 

Developer
Posts: 70
Registered: ‎01-02-2009
My Device: Not Specified

Re: Is it possible to read and display multiple images?

You can use something like this to download the image...

 

 

StreamConnection connection = (StreamConnection) Connector.open(url);
DataInputStream iStrm = connection.openDataInputStream();
Image im = null;
ByteArrayOutputStream bStrm = null;
byte imageData[];
int length = (int) connection.getLength();
if (length != -1) {
imageData = new byte[length];

// Read the png into an array
// iStrm.read(imageData);
iStrm.readFully(imageData);
} else // Length not available...
{
bStrm = new ByteArrayOutputStream();
int ch;
while ((ch = iStrm.read()) != -1)
bStrm.write(ch);
imageData = bStrm.toByteArray();
bStrm.close();
}

 

 

 

 imageData - contains the byte array of your image.

 

then you can use the below code to create image.

 

image = EncodedImage.createEncodedImage(imageData, 0, imageData.length);

 

then you can use it.

 

 

---------------------
Best Regards,
Kannabiran.
---------------------
Don't forget to mark your post as solved if you got answer. And give kudos.
Developer
Posts: 70
Registered: ‎01-02-2009
My Device: Not Specified

Re: Is it possible to read and display multiple images?

if you have any problem(downloading image), please refer the below links

 

http://www.java2s.com/Code/Java/J2ME/Downloadandviewapngfile.htm

http://www.java-tips.org/java-me-tips/midp/how-to-download-an-image-from-a-web-server.html

---------------------
Best Regards,
Kannabiran.
---------------------
Don't forget to mark your post as solved if you got answer. And give kudos.