File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MemoryImageSource and byte arrays

 
Eric Hoskland
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't for the life of me figure out a way to provide MemoryImageSource with a byte array and it gives me back an image.
My byte array stores values like this:
{R0,G0,B0,R1,G1,B1, etc..}
It has a contructor for a bytearray but I can't figure out Colorspace,ColorModel,SampleModel, Databuffer, ColorSpace, PixelInterleavedSomethingorOther combination to create an image
Thanks in advance
Eric
 
Craig Wood
Ranch Hand
Posts: 1535
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is an example in the MemoryImageSource api.
 
Eric Hoskland
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
from the memoryimagesource API
pixels = new int[size];
.....
....
source = new MemoryImageSource(width, height, pixels, 0, width);

reread what I said and you'll realize why this isn't what I want.
reconstructing a byte array into an int array is very inefficient. That's like 160*120*3 operations per image without an alpha channel.
 
Don Kiddick
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
160 * 120 * 3 is not many operations. This will probably take less than a millisecond.
D.
 
Don Kiddick
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
takes between 0.5 and 0.6 milliseconds to do the conversion :

Can you wait that long?
D.
 
Eric Hoskland
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With speed considerations aside the solution of bit shifting and or'ing in all the values upon every single reception of a new image is quite messy. The entire purpose of programming in 3rd generation languages is to give into the OO paradigm and relieve ourselves from such tedious non-harmonious solutions. If we're going to call the solution above acceptable then why not just do the whole thing in assembly. Why even try to use the layer of abstraction that makes java so fun. So with that in mind here's the solution to what I asked:

Now all you have to do is refill the byte array b_pixels and display the new buffered image..Works excellent for displaying images coming from an input stream of some kind..just use b_pixels as the array to stream into and display bImage.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic