Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

Creating an Image from a rgb byte array

Thread view: 
E. Naubauer - 18 Feb 2006 15:16 GMT
Hello

I'm trying to convert a byte array to an image Object via
MemoryImageSource. Three bytes together are a pixel, one byte per component:

[r][g][b][r][g][b][r][g][b][r][g][b][r][g][b]....

[] = one byte

This is the code:

int w = 176,h = 144;
Image output = null;
byte rgbBuffer[] = <image data with length w * h>

ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        ComponentColorModel cm = new ComponentColorModel(cs,new int[]
{8,8,8},false,false,ComponentColorModel.OPAQUE,DataBuffer.TYPE_BYTE);
       
        output =  Toolkit.getDefaultToolkit().createImage(new
MemoryImageSource(w, h, cm,dim, 0, w));

It works if I use a buffer of type int[] with packed RGBA values and
DataBuffer.TYPE_INT.  However, with the above configuration, the image
remains black when drawn.

I'm starting to wonder if createImage actually works with interleaved
component data. I used a writable raster before, but it was awfully slow.

If anyone has a solution for this problem, please tell it.
Thanks in advance.
Knute Johnson - 23 Feb 2006 22:58 GMT
> Hello
>
[quoted text clipped - 28 lines]
> If anyone has a solution for this problem, please tell it.
> Thanks in advance.

You need a BufferedImage.

Signature

Knute Johnson
email s/nospam/knute/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.