Re: how to use a byte array to create image



jimgardener wrote:
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;
}

If what you have is truly 'image data' in the Java sense then creating the image from a byte array is done by converting the bytes to an int[] and setting the data of the BufferedImage with setRGB(). From there use ImageIO to write out your TIFF file.

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.

--

Knute Johnson
email s/nospam/knute2008/

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
.



Relevant Pages

  • my fingerprint identification project , plz help
    ... i send you to all code, GUI and fingerprint database. ... BufferedImage thini1,thini2; ... public void addWidgets() ... return int 1 value if cancel is choosen ...
    (comp.lang.java.programmer)
  • Application Structure
    ... public int undoFlag = 0; ... ButtCreator butt1 = new ... public void updateUndoAr{ ... BufferedImage last = lLsUndo.get; ...
    (comp.lang.java)
  • application Structure
    ... public int undoFlag = 0; ... ButtCreator butt1 = new ... public void updateUndoAr{ ... BufferedImage last = lLsUndo.get; ...
    (comp.lang.java.programmer)
  • Re: Graphics - how to show partial progress.
    ... BufferedImage does not clone easily, ... The code now publishes intermediate results as a Raster which the ... final int biXpos = 30; ...
    (comp.lang.java.help)
  • Re: Graphics - how to show partial progress.
    ... BufferedImage does not clone easily, ... The code now publishes intermediate results as a Raster which the ... final int biXpos = 30; ...
    (comp.lang.java.help)