• 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

Getting a byte array from an Image in MIDP 1.0

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello.
With using I can make an Image object from a byte array. But I need to use the opposite operation to get a byte array again from an Image or Graphics object in MIDP 1.0. Is there a possibility? Maybe deriving Image and using some undocumented protected methods? In MIDP 2.0 there is Image.getRGB that I might be able to use but I am restricted to version 1.0.
Thanks in advance.
Christian Wolf
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This can't be done. At least, I don't know how to do it. Perhaps jad (google cache) can help?
 
Christian Wolf
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This can't be done. At least, I don't know how to do it. Perhaps jad (google cache) can help?


Would be a nice hack to decompile the Canvas.class and maybe make another implementation of it. But anyway, I have found a different way to surround my problem. Thanks.
Christian Wolf
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about sharing with the community, Christian?
 
Christian Wolf
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

How about sharing with the community, Christian?


*smile* Unfortunately, it's a bad solution, in my opinion. The point is that I receive one or more images as byte streams and that I have to store them in memory for some time, maybe 5, maybe 30 minutes until the user decides to process them. I want to show them on the screen, therefore I need to create Images with using Image.createImage (which by the way does not work, I get a IllegalArgumentException with all PNG, GIF and JPG). Now the same data is stored two times in memory. As I wanted to avoid this, I wanted to delete the byte array and later regenerate it from the Image. This does not work. Therefore I keep both the Image and the byte array in memory and process the byte array later if needed.
Christian Wolf
 
Christian Wolf
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

therefore I need to create Images with using Image.createImage (which by the way does not work, I get a IllegalArgumentException with all PNG, GIF and JPG)


I just found out that converting a bytearray to string and back messes up the data due to some encoding issues. So if you sometimes get a byte array, do not convert this unless you know what you do. Using the original byte array for Image.createImage works quite fine.
Christian Wolf
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Christian:
Have you thought about puting the byte array into the RMS. This will move it out of memory, but make it available for the future. Also, if the user exits your app (or the app or jvm crashes... ), the image are still available.
The RMS API is quite easy to use, especially with byte arrays.
Some notes: The RMS implementation is slow to create new records, but writing and reading are "relatively" fast. So I would recommend that if can leverage the fact that your images are all the same size (i.e. the byte array is always the same size), you can reuse the records in the RMS.
Good luck.
Nancy

Originally posted by Christian Wolf:

I just found out that converting a bytearray to string and back messes up the data due to some encoding issues. So if you sometimes get a byte array, do not convert this unless you know what you do. Using the original byte array for Image.createImage works quite fine.
Christian Wolf

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
meybe you can use it: http://www.corej2me.com/DeveloperResources/sourcecode/networking/downloadPng/index.shtml
???
if you can change
Connection conn = Connector.open(url);
with
Connection conn = Connector.open("file://myfile.dat");
and look FlashSMS (http://www.geocities.com/rizapn/)
[ March 04, 2004: Message edited by: Alex Tk ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic