(keitai-l) Re: images on the scratchpad

From: César Fernández <cfernandez_at_insidelabs.com>
Date: 03/17/04
Message-ID: <40582BFC.1080205@insidelabs.com>
Hi Claus,

I am not sure about what you want to do, but I hope this will help you.
First you have to download the image from internet, doing something like 
this

    String url = IApplication.getCurrentApp().getSourceURL() + "/icons/" 
+ imagen;
    byte[] b = null; int len = 0;
    HttpConnection conn = null;
    OutputStream out = null;
    InputStream in = null;
   
    try{
         conn = (HttpConnection)Connector.open(url, Connector.READ);
         conn.setRequestMethod(HttpConnection.GET);
         conn.connect();
         len = (int)conn.getLength();
         in = conn.openInputStream();
         b = new byte[len];
         in.read( b, 0, len );
         in.close(); conn.close();
    } catch ( Exception e ) {
         System.out.println("No se encuentra imagen: " + url);
    }

Now you have the image in a byte stream, like you say. So lets store it 
on the scratch pad

try{
        out = Connector.openOutputStream("scratchpad:///0;pos=0");
        out.write(b);
        out.close();
    } catch ( Exception e ) {
        System.out.println("Error al grabar " + imagen + " en 
'scratchpad:///0;pos=0");
    }

I hope this helps you.

----------------------------------------------------
Cesar Fernandez
www.insidelabs.com



Claus H&#246;fele wrote:

>Hi Cesar,
>
>May I ask you how you store the images in scratchpad? Is it possible to convert MediaImages in a byte stream or do I have to use the Connector methods?
>
>If you don't mind it would be great if you could share some code.
>
>Thanks a lot,
>Claus
>
>-----Original Message-----
>From: C&#233;sar Fern&#225;ndez [mailto:cfernandez@insidelabs.com] 
>Sent: Friday, March 12, 2004 5:26 AM
>To: keitai-l@appelsiini.net
>Subject: (keitai-l) images on the scratchpad
>
>
>Hello all,
>
>I had an application that use some images whose total size is greater 
>than 30k. To avoid this problem I store the images on the server as .gif 
>files. I want my application to download them. I can do this, but in 
>order to avoid downloading the images each time the application executes 
>I want to store them in the scratch pad the first time the application 
>executes, and get the images from the scratch pad after the first 
>execution. The problem is, how to get the images from the scratch pad 
>after theyre stored?
>Suppose I save 10 gifs on the scratch pad. I know the size of each gif, 
>so I can use this information to get each image, like this
>
>MediaImage mi = MediaManager.getImage("scratchpad:///0;pos=5222");
>
>But I am not sure of what is stored at mi.  Only one image or all the 
>bytes after position 5222 ??? Because if only the image saved at 
>position 5222 is stored at mi, the problem is solved, but I am not sure 
>if things are done this wa or mi gets all the bytes in the scratch pad 
>after position 5222.
>
>This mail was sent to address claus.hoefele_at_sonyericsson.com Need archives? How to unsubscribe? http://www.appelsiini.net/keitai-l/ 
>
>
>_______________________________________________________________________
>... and the winner is... WEB.DE FreeMail! - Deutschlands beste E-Mail
>ist zum 39. Mal Testsieger (PC Praxis 03/04) http://f.web.de/?mc=021191
>
>
>  
>
Received on Wed Mar 17 12:44:32 2004