Hello,
If I have a PNG image on my server, how do I go about downloading it and placing the image into my midp application? Mainly the part of reading the image over the http interests me, if its even possible.
Hello,
If I have a PNG image on my server, how do I go about downloading it and placing the image into my midp application? Mainly the part of reading the image over the http interests me, if its even possible.
I have tried this once converting the image into Base64. What I did is encrypted the image on the server side into Base64 code and then after reading it into my midlet decrypted it back.
It worked for me.
All the very best.
Hi,
This is the code you can work upon..This will download and save the image in yr application..
any query will be answered...
*-------------------------------------------------*/
private Image getImage(String url) throws IOException
{
ContentConnection connection = (ContentConnection) Connector.open(url);
// * There is a bug in MIDP 1.0.3 in which read() sometimes returns
// an invalid length. To work around this, I have changed the
// stream to DataInputStream and called readFully() instead of read()
// InputStream iStrm = connection.openInputStream();
DataInputStream iStrm = connection.openDataInputStream();
ByteArrayOutputStream bStrm = null;
Image im = null;
try
{
// ContentConnection includes a length method
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();
}
// Create the image from the byte array
im = Image.createImage(imageData, 0, imageData.length);
}
finally
{
// Clean up
if (iStrm != null)
iStrm.close();
if (connection != null)
connection.close();
if (bStrm != null)
bStrm.close();
}
return (im == null ? null : im);
}
Thnxs
Thanks with Regards,
R a j - The K e r n e l
Join Delhi-NCR Nokia Developer's Community,