Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to convert image to bytearray in MIDlet

 
Theeranit Pongtongmuang
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I'm very new for Java I/0.

I want to convert Image object to byte array (byte[])
This is my code for creating Image.


Image myImage =null;
try {
myImage = Image.createImage("/myImage.png");
} catch (IOException ex) {
ex.printStackTrace();
}

How can I convert "myImage" to byte[] with Java I/0

Please could you give me a good suggestion and code snippet.

Thanks a lot.
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you use the combination of FileInputStream and ByteArrayInputStream to get the byte array? With that you don't need to convert Image to byte array anymore.
 
Theeranit Pongtongmuang
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for your suggestion.

I get an idea to solve this problem.
 
Cob is sand, clay and sometimes straw. This tiny ad is made of cob:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!