how to use a byte array to create image
- From: jimgardener <jimgardener@xxxxxxxxx>
- Date: Wed, 25 Jun 2008 08:17:04 -0700 (PDT)
i have a byte array that i contains image data.Can someone tell me how
i can use it to create a TIFF image with JAI api? I created a
bufferedimage etc as below..but i don't know how to use my byte array
to create the image
BufferedImage result = mycreateImage(width, height);
WritableRaster raster = result.getRaster();
where
private static BufferedImage mycreateImage(int width, int height) {
int colorSpace = ColorSpace.CS_sRGB;
ColorSpace cs = ColorSpace.getInstance(colorSpace);
boolean hasAlpha = false;
boolean isAlphaPremultiplied = true;
int transparency = java.awt.Transparency.OPAQUE;
int dataType = java.awt.image.DataBuffer.TYPE_USHORT;
java.awt.image.ColorModel cm = new
java.awt.image.ComponentColorModel(
cs,
hasAlpha,
isAlphaPremultiplied,
transparency,
dataType
);
int numBands = 3;
java.awt.image.SampleModel sm = new
java.awt.image.BandedSampleModel(
dataType,
width,
height,
numBands
);
java.awt.Point location = null;
java.awt.image.WritableRaster raster =
java.awt.image.Raster.createWritableRaster(sm, location);
java.util.Hashtable properties = null;
BufferedImage result = new BufferedImage(
cm,
raster,
isAlphaPremultiplied,
properties
);
return result;
}
.
- Follow-Ups:
- Re: how to use a byte array to create image
- From: Knute Johnson
- Re: how to use a byte array to create image
- From: Tom Anderson
- Re: how to use a byte array to create image
- Prev by Date: Re: Using SAX parser how to identify values for duplicate tag name.
- Next by Date: Re: how to use a byte array to create image
- Previous by thread: Socket, InputStream and close
- Next by thread: Re: how to use a byte array to create image
- Index(es):
Relevant Pages
|