• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Failed to load byte array of an png image into an midp application

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I am facing problem as heavy png files increases the size of my J2me application. No i tried to convert these png files to an byte array and then load this byte array at run time using the method
Image.createImage(byte[] imageData, int imageOffset, int imageLength)
But failed as when i use this image into my app it shows nothing in place of image. means i go blank screen.
Is the anybody who has worked on the same and can help me for the above problem.

Waiting for reply.
Regards,
Rishi Tyagi
[ January 24, 2003: Message edited by: Rishi Tyagi ]
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't completely understand your problem. You can either bundle a PNG file with your MIDlet suite (thus increasing the size of your JAR file) or you can use a byte array. This byte array must be the same format as a PNG file.
The question becomes, how are you creating this byte array? There are 2 obvious ways that I can think of including loading it versus creating it manually in memory. Loading it is just a variation of loading the PNG file however and so doesn't solve your problem. Creating it manually is a little painful and involves a little research.
I've gone through this later process and recommend you look at the PNG specification (version 1.0), RFC 1950 and RFC 1951 (for the compression stuff you'll need to understand for the IDAT chunk). It is possible to create a PNG file in memory on the devices and since one of the compression methods of the "deflate" algorithm is "uncompressed", you can use raw image data to populate your byte array.
You can use a pallette chunk (for indexed colour models) or not (for direct colour models). I suggest using a pallette colour model since it allows you to also use a transparency chunk (some devices support image transparency). Plus the image data is much smaller (one byte per pixel if you use 256 colours).
The big negative thing about creating the PNG image data in memory however is that you have to create a CRC (checksum) for each chunk. Whilst programming it is easy, it takes time to perform each time and it slows your app down. Also for IDAT chunk you need to create an Addler-32 checksum.
It's a pretty nasty and round about way of doing it but unless your using something like the Nokia gaming API, there's no other way to getting direct pixel access to the screen.
Cheers,
PK
 
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are reading the PNG image data from a HTTP stream make sure that you open a DataInputStream using
dis = httpCon.openDataInputStream();
// And the call the method to read the png image data
dis.readFully(b);
I faced a similar problem since I used to use the method 'read(b)' rahter than readFully(). You can look up the difference in both these methods in the doc.
regards
V
 
Rishi Tyagi
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul & Vivek,
A very warm thankyou for the replies.
Now i am describing the application
1- My Application does not use HTTP Connection Means i does not interact with any back-end application.
2- What i want to do make a simple animated graphic-rich game (like car race or space war etc)
Now if i want to make this type of graphic rich application then i will have to use images because using j2me api i can't generate good quality of graphics through programming.

Now problem is
1- If i adds png images to the application then the size of the whole application increase to 10 times of the simple application as each png image file is of atleast 4kb to 10 kb, This big size of the application is not supported by most of the handsets.
2- I thought to read these png images into byte array then i write them into a txt file in the series of 0's and 1's , planned to read the same at runtime whenever i will have to put an image into the application.
BUT FAILED
For Reading Images :- I used simple java program to read the png image files and converted that into the array or bits.
Putting Image :- Now at run time i read the txt file and picked the whole stream of 0's and 1's (saved in txt file) in a byte array and used
Image.createImage(byte[] imageData, int imageOffset, int imageLength) method
to convert this byte array into the image
But failed as it shows nothing on the screen neither it gives any error.

I would be highly obliged if anybody can solve my this problem
or
can tell me the way how can i make Graphic rich and animated application in j2me more efficiently.
What is the right way to add a graphic in the j2me application without increasing the size of the applicatiopn too much.
With Best Regards,
Rishi
[ March 10, 2003: Message edited by: Rishi Tyagi ]
 
Vivek Viswanathan
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
That sounds like a really interesting and nice problem, you want to take this one Paul ?

Vivek
 
Rishi Tyagi
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Vivek,
You are right, its interesting, although i am in habit of enjoying the problems but right now bulbs in my mind has been pretended to be switched-off ,
That is why either i am thinking in a wrong way to solve the problem or there is some pitfals in my code and i am not able to find that.
Is there anybody who can guide me on the same

Looking forward for a positive response..
With Best Regards
Rishi
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic