You Are Here:

Community: Developer Discussion Boards

#1 Old creating image - 2003-09-12, 06:57

Join Date: Mar 2003
Posts: 181
Location: Hyderabad
Send a message via Yahoo to j2me_raj
j2me_raj
Offline
Regular Contributor
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
Reply With Quote

#2 Old 2003-09-12, 08:53

Join Date: Jun 2003
Posts: 414
Location: Hungary
kisember
Offline
just a baker
Did you set the MIME type of asp generated image?
Reply With Quote

#3 Old 2003-09-12, 09:01

Join Date: Mar 2003
Posts: 181
Location: Hyderabad
Send a message via Yahoo to j2me_raj
j2me_raj
Offline
Regular Contributor
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;
}
Reply With Quote

#4 Old 2003-09-12, 09:08

Join Date: Jul 2003
Posts: 1,094
Location: Finland, Tampere
doctordwarf
Offline
Super Contributor
At which point are you getting NullPointerException?
Reply With Quote

#5 Old 2003-09-12, 10:56

Join Date: Jun 2003
Posts: 414
Location: Hungary
kisember
Offline
just a baker
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.
Reply With Quote

#6 Old 2003-09-12, 19:51

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
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.
Reply With Quote

#7 Old 2003-09-13, 05:16

Join Date: Mar 2003
Posts: 181
Location: Hyderabad
Send a message via Yahoo to j2me_raj
j2me_raj
Offline
Regular Contributor
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....
Reply With Quote

#8 Old 2003-09-13, 15:33

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
What kind of problems?

Graham.
Reply With Quote

#9 Old 2003-09-15, 04:41

Join Date: Mar 2003
Posts: 181
Location: Hyderabad
Send a message via Yahoo to j2me_raj
j2me_raj
Offline
Regular Contributor
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
Reply With Quote

#10 Old 2003-09-15, 22:05

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
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.
Reply With Quote

#11 Old 2003-09-16, 05:45

Join Date: Mar 2003
Posts: 181
Location: Hyderabad
Send a message via Yahoo to j2me_raj
j2me_raj
Offline
Regular Contributor
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
Reply With Quote

#12 Old 2003-09-16, 09:25

Join Date: Mar 2003
Posts: 2,280
Location: Israel
shmoove
Offline
Forum Nokia Champion
Quote:
Image img2 = Image.createImage(data, 3843, 6996);
If you say that the data file is 6996 bytes, then it should probably be:
Code:
Image img2 = Image.createImage(data, 3843, 6998);
Don't forget arrays are zero-based in Java...

shmoove
Reply With Quote

#13 Old 2003-09-16, 22:15

Join Date: Aug 2003
Posts: 134
dannyc4
Offline
Regular Contributor
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 With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia