| Reply | « Previous Thread | Next Thread » |
|
Hi all
creating image connecting to site with image over http is no problem. suppose if i want to create image by connecting to asp page which gives me binary data of png image.....please help me out with a sample...... i am trying but i am getting nullpointer exception...... thanks rajsekhar@valuelabs.net |
|
Did you set the MIME type of asp generated image?
|
|
what mime type i need to set????
my code is as follows.... httpc = (HttpConnection) Connector.open(queryString); httpc.setRequestMethod(HttpConnection.GET); length = (int) httpc.getLength(); if (length > 200 ) { DiStrm = httpc.openDataInputStream(); byte imageData[]; if (length != -1) { imageData = new byte[length]; DiStrm.readFully(imageData); }else { ByteArrayOutputStream bStrm = new ByteArrayOutputStream(); int ch; while ((ch = DiStrm.read()) != -1) { bStrm.write(ch); } imageData = bStrm.toByteArray(); bStrm.close(); } iFin = Image.createImage(imageData, 0, imageData.length); restVal = true; } |
|
At which point are you getting NullPointerException?
|
|
I mean you could set the MIME type on the server side to image/png. But I'm wrong. It have to work with any byte array regardless of any MIME type or content, if it's a valid png.
At first sight your code also have to work if queryString is correct. |
|
I've just used your code, and it retrieved an image fine for me.
My guess is, your length field is less that 200, in which case you never create an image, and iFin gets left as null. (By the way, your inner 'if' is redundant... if length > 200, it must also be != -1). Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
hi grahamhughes
yeah my code is working fine for me too.....previously the data i m getting is not well formatted.... well i have one more question for you all.... can anyone worked on retrieving multiple images from sever??????.......i need to retreive 5 images ...which are individually placed.......please let me know if anyone has worked in realtime........ i can retrieve them in a loop.....but still i m facing problems in real phone.....where as it is working fine in emulator..... please help me out.... |
|
What kind of problems?
Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
hi gramham
its taking time to retrieve images from server in a loop.......and its like forever waiting........actually i have called a method by starting a thread....that is i am invoking a method from run() in the method which i invoked i am writing code to connect tro server in a for loop to retrieve images..... can you give me any better solution thanks raj |
|
Hi Raj,
According to Nokia ("Efficient MIDP Programming"), there is a high latency time for each HTTP request, of several seconds. If you're fetching five files in five requests, you could be looking at anything between 10 and 30 seconds of dead time, on top of the actual time needed to transfer the data. A solution might be to transfer all the images in one go... concatenating them to a single data stream on the server, then separating them on the phone. This means you would have one request instead of five, so much less latency time. If Nokia's figures are accurate, that should mean a significant reduction in time. If you try it, I'd be very interested to know what difference it makes. Cheers, Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
Hi Graham
thanks for your reply. but my question is how to concatenate the data from server??? this is what i am facing problem...do you have any sample code where in i can do what you said. i tried concatenating 2 pngs using dos command and put the whole data into a dat file. in this i already knew the size. one file is 3482 bytes and the other is 3483 so total size of .dat file is 6996. i am receiveing the data fine. but when i am trying to create images as follows Image img1 = Image.createImage(data, 0, 3842); i am successful here. but if i try to create the other image i am getting array index out of bounds exception. Image img2 = Image.createImage(data, 3843, 6996); i also tried Image img2 = Image.createImage(data, 3842, 6996); but no use. can you try this let me knw if you are successful??? thanks Raj |
|
Quote:
Code:
Image img2 = Image.createImage(data, 3843, 6998); shmoove |
|
createImage(byte[] imagedata, int imageoffset, int imagelength)
So, the error is the second image is 3843 bytes of length, not the complete filesize of 6996 . Try: createImage(data, 0, 3842); // array offset =0, imagelength=3842 bytes createImage(data, 3842, 3843); // offset = 0 + size_of_previous = 3842, imagelength=3843 bytes |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|