how to use a byte array to create image



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;
}
.



Relevant Pages

  • Re: how to get byte[] from an image
    ... A byte array or an int array? ... It's probably trivial to adapt it to return an int[] ... {@link BufferedImage}. ... internal DataBuffer banks isn't 1. ...
    (comp.lang.java.programmer)
  • Re: how to return an Array ?
    ... What datatype should I use ... I tried using an "Array" but there was a compilation error. ... public Array setReviewAll2 (int intNumQn) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: how to use a byte array to create image
    ... image from a byte array is done by converting the bytes to an int[] and setting the data of the BufferedImage with setRGB. ... If the 'image data' is an array of bytes read from some file then I would have to know what sort of file to tell you how to proceed. ... I have some JPEG files from which I need to create images suitable for transmission across a network and I note that BufferedImage does not implement Serializable. ...
    (comp.lang.java.programmer)
  • Re: byte[] to Image
    ... setRGB(int, int, int) on a newly created BufferedImage for every pixel in ... the array. ...
    (comp.lang.java.programmer)
  • (patch for Bash) regex case statement
    ... Following up on my previous patch for regex conditional tests, ... /* Return an array of strings; ... int dollarflag, zeropad, compareflag; ... SHELL_VAR *var; ...
    (comp.unix.shell)