RE: [JAVA2D] converting Java Image to Mac OS native image
Seems like nobody has answered this (or I missed it) so I'll give
you my thoughts. I'm not that familiar with images in Cocoa, it's
been a while since i wrote any Cocoa code. But without knowing the
API for, say, NSImage, I'll tell you what i can guess.
The first thing I'll say is, in my opinion, you do NOT want to deal
with images at the JPEG or GIF or format level. I would get a hold
of a RenderedImage (or BufferedImage) and go from there, that way
you don't care about the source format.
The fundamental pieces of a RenderedImage are its SampleModel, its
ColorModel, and its Rasters -- one Raster if the image is not tiled,
which for normal-sized images is probably the case.
You'll have to figure out the NSImage API and see if it makes sense
to subclass it, or to construct one with data you get from Java.
The SampleModel and ColorModel just consist of some parameters like
number of bands, bits per pixel etc. Those things you should be able
to convert into whatever an NSImage needs.
The last piece is the Raster, which itself consists of a DataBuffer
and a SampleModel. The SampleModel usually has the same values as
the one you get from the RenderedImage, so the only item of note is
the DataBuffer. And when you decompose this, it's really just an
array of whatever data type your image is (typically byte unless
you have packed pixels or 16-bit data).
So the fundamental part of passing your image from Java to JNI/native
code is passing the data in the DataBuffer, along with whatever
properties you need to build the NSImage. If you want to process
tiled images, you may want to do things slightly differently, since
you don't want to load all the tiles into the heap at once.
Hope this helps,
> -----Original Message-----
> From: Discussion list for Java 2D API
> [mailto:JAVA2D-INTEREST@JAVA.SUN.COM] On Behalf Of Rob Ross
> Sent: Wednesday, September 20, 2006 3:42 PM
> To: JAVA2D-INTEREST@JAVA.SUN.COM
> Subject: [JAVA2D] converting Java Image to Mac OS native image
> Hi. Long shot here, but having no luck finding sample code...
> I'm writing some JNI code that will run on Mac OS X. I need
> to call a native method and pass it a Java image object, and
> be able to convert that to a Mac OS X native image type, like
> an NSImage.
> I'm pretty sure that the Java2D team knows how to do for
> Windows, since it must happen at some point in your Java 2D
> Windows native/ implementation code.
> Maybe I just need to be able to pass the Java image data as a
> byte in some well-known byte structure that represents a
> JPEG or GIF, etc, and I can convert it from there.
> Any pointers?
> Rob Ross, Lead Software Engineer
> E! Networks
> "Beware of he who would deny you access to information, for
> in his heart he dreams himself your master." -- Commissioner
> Pravin Lal
> To unsubscribe, send email to email@example.com and
> include in the body of the message "signoff JAVA2D-INTEREST".
> For general help, send email to firstname.lastname@example.org and
> include in the body of the message "help".
To unsubscribe, send email to email@example.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
firstname.lastname@example.org and include in the body of the message "help".