java.lang.Object
java.awt.image.Raster
- Direct Known Subclasses:
- WritableRaster
- See Also:
- Top Examples, Source Code,
DataBuffer
,
SampleModel
,
PixelInterleavedSampleModel
,
BandedSampleModel
,
SinglePixelPackedSampleModel
,
MultiPixelPackedSampleModel
public static WritableRaster createBandedRaster(int dataType,
int w,
int h,
int scanlineStride,
int[] bankIndices,
int[] bandOffsets,
Point location)
- See Also:
- ArrayIndexOutOfBoundsException, IllegalArgumentException, RasterFormatException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static WritableRaster createBandedRaster(int dataType,
int w,
int h,
int bands,
Point location)
- See Also:
- ArrayIndexOutOfBoundsException, RasterFormatException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static WritableRaster createBandedRaster(DataBuffer dataBuffer,
int w,
int h,
int scanlineStride,
int[] bankIndices,
int[] bandOffsets,
Point location)
- See Also:
- NullPointerException, IllegalArgumentException, RasterFormatException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Raster createChild(int parentX,
int parentY,
int width,
int height,
int childMinX,
int childMinY,
int[] bandList)
- See Also:
- RasterFormatException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public WritableRaster createCompatibleWritableRaster()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public WritableRaster createCompatibleWritableRaster(int w,
int h)
- See Also:
- RasterFormatException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public WritableRaster createCompatibleWritableRaster(int x,
int y,
int w,
int h)
- See Also:
- RasterFormatException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public WritableRaster createCompatibleWritableRaster(Rectangle rect)
- See Also:
- NullPointerException, RasterFormatException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static WritableRaster createInterleavedRaster(int dataType,
int w,
int h,
int scanlineStride,
int pixelStride,
int[] bandOffsets,
Point location)
- See Also:
- IllegalArgumentException, RasterFormatException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static WritableRaster createInterleavedRaster(int dataType,
int w,
int h,
int bands,
Point location)
- See Also:
- RasterFormatException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static WritableRaster createInterleavedRaster(DataBuffer dataBuffer,
int w,
int h,
int scanlineStride,
int pixelStride,
int[] bandOffsets,
Point location)
- See Also:
- NullPointerException, RasterFormatException, IllegalArgumentException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static WritableRaster createPackedRaster(int dataType,
int w,
int h,
int bands,
int bitsPerBand,
Point location)
- See Also:
- IllegalArgumentException, RasterFormatException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static WritableRaster createPackedRaster(int dataType,
int w,
int h,
int[] bandMasks,
Point location)
- See Also:
- IllegalArgumentException, RasterFormatException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static WritableRaster createPackedRaster(DataBuffer dataBuffer,
int w,
int h,
int scanlineStride,
int[] bandMasks,
Point location)
- See Also:
- NullPointerException, RasterFormatException, IllegalArgumentException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static WritableRaster createPackedRaster(DataBuffer dataBuffer,
int w,
int h,
int bitsPerPixel,
Point location)
- See Also:
- NullPointerException, RasterFormatException, IllegalArgumentException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static Raster createRaster(SampleModel sm,
DataBuffer db,
Point location)
- See Also:
- NullPointerException, RasterFormatException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Raster createTranslatedChild(int childMinX,
int childMinY)
- See Also:
- RasterFormatException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static WritableRaster createWritableRaster(SampleModel sm,
DataBuffer db,
Point location)
- See Also:
- NullPointerException, RasterFormatException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static WritableRaster createWritableRaster(SampleModel sm,
Point location)
- See Also:
- RasterFormatException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[1106]Work for single image TIFF but not for multiple image TIFF
By sreenivasn_2000 { at } yahoo { dot } com on 2005/01/14 08:55:46 Rate
package ucc.util;
import java.io.*;
import java.util.*;
import java.awt.*;
import org.apache.log4j.*;
import java.awt.image.*;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.PdfPage;
import com.lowagie.text.pdf.PdfCopyMerge;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.Chunk;
import com.lowagie.text.Cell;
import com.lowagie.text.Element;
import com.lowagie.text.Phrase;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Table;
import com.lowagie.text.Image;
import com.lowagie.text.Document;
import com.lowagie.text.PageSize;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Font;
import com.lowagie.text.HeaderFooter;
import com.sun.media.jai.codec.SeekableStream;
import com.sun.media.jai.codec.FileSeekableStream;
import com.sun.media.jai.codec.TIFFDecodeParam;
import com.sun.media.jai.codec.TIFFEncodeParam;
import com.sun.media.jai.codec.ImageDecoder;
import com.sun.media.jai.codec.ImageCodec;
public class PDFUtil {
private static final Logger LOG = Logger.getLogger ( PDFUtil.class ) ;
public static final void appendAttachment ( String fileName, Document doc, PdfWriter writer )
throws Exception {
fileName = System.getProperty ( "java.io.tmpdir" ) +"/"+fileName;
if ( ImageUtil.isImage ( fileName ) ) {
appendImage ( fileName, doc, writer ) ;
}
else if ( ImageUtil.isPDF ( fileName ) ) {
appendPDF ( fileName, doc, writer ) ;
}
else {
Paragraph errorMessage = new Paragraph ( ) ;
errorMessage.setAlignment ( Element.ALIGN_LEFT ) ;
errorMessage.setKeepTogether ( true ) ;
errorMessage.add ( new Chunk ( fileName.substring ( fileName.lastIndexOf ( "/" ) +1 ) +" is an unsupported image type.", new Font ( Font.HELVETICA, 10, Font.NORMAL ) ) ) ;
Table table = new Table ( 1 ) ;
table.setTableFitsPage ( true ) ;
table.setWidth ( 100 ) ;
table.setBorder ( 0 ) ;
table.setPadding ( 0 ) ;
table.setSpacing ( 0 ) ;
Cell cell = new Cell ( errorMessage ) ;
cell.setHorizontalAlignment ( Element.ALIGN_LEFT ) ;
cell.setVerticalAlignment ( Element.ALIGN_TOP ) ;
cell.setBorder ( 0 ) ;
table.addCell ( cell ) ;
doc.add ( table ) ;
}
}
public static final void appendImage ( String fileName, Document doc, PdfWriter writer )
throws Exception {
try {
if ( ImageUtil.isTif ( fileName ) ) {
LOG.debug ( "We are dealing with a tiff ..." ) ;
File file = new File ( fileName ) ;
SeekableStream s = new FileSeekableStream ( file ) ;
///Sreenivas added
ImageDecoder dec = ImageCodec.createImageDecoder ( "tiff", s, null ) ;
System.out.println ( "Number of images in this TIFF: " + dec.getNumPages ( ) ) ;
PdfContentByte cb = writer.getDirectContent ( ) ;
for ( int k = 0; k < dec.getNumPages ( ) ; ++k ) {
RenderedImage ri = dec.decodeAsRenderedImage ( k ) ;
Raster ra = null;
//Raster ra = ri.getData ( ) ;
LOG.debug ( " RI width=" + ri.getWidth ( ) ) ;
LOG.debug ( " RI height=" + ri.getHeight ( ) ) ;
int rh = ra.getHeight ( ) ;
LOG.debug ( "Raster rh :" + rh ) ;
int rw = ra.getWidth ( ) ;
LOG.debug ( "Raster rw :" + rw ) ;
int xi=ri.getNumXTiles ( ) ;
LOG.debug ( " RI X tiles=" + xi ) ;
int yi=ri.getNumYTiles ( ) ;
LOG.debug ( " RI Y tiles=" + yi ) ;
LOG.debug ( " RI tile height=" + ri.getTileHeight ( ) ) ;
LOG.debug ( " Returns tile=" + ri.getTile ( xi,yi ) ) ;
//Raster ra = null;
BufferedImage bi = null;
boolean isbuffimgcreated=false;
for ( int i=0;i < =ri.getNumYTiles ( ) ;i++ )
{
ra = ri.getTile ( 0, i ) ;
LOG.debug ( " Ra tiles=" + ra ) ;
if ( ! isbuffimgcreated ) {
bi = new BufferedImage ( ri.getColorModel ( ) ,Raster.createWritableRaster ( ri.getSampleModel ( ) , ra.getDataBuffer ( ) , null ) , false, new Hashtable ( ) ) ;
isbuffimgcreated=true;
LOG.debug ( " in BI creation loop" ) ;
} else {
bi.setData ( ra ) ;
LOG.debug ( " in BI already created loop" ) ;
}
LOG.debug ( " In tiles loop num=" + i ) ;
}
Image img = Image.getInstance ( bi, null, true ) ;
img.scalePercent ( 36 ) ;
float y = doc.top ( ) - img.scaledHeight ( ) ;
img.setAbsolutePosition ( 0, y ) ;
LOG.debug ( "Top Position..."+ y ) ;
doc.newPage ( ) ;
cb.addImage ( img ) ;
}
}
else {
java.awt.Image coreImage = Toolkit.getDefaultToolkit ( ) .createImage ( fileName ) ;
Image image = Image.getInstance ( coreImage, null ) ;
image.setAbsolutePosition ( 0, 0 ) ;
doc.newPage ( ) ;
doc.add ( image ) ;
}
LOG.debug ( "Added image "+fileName ) ;
}
catch ( Throwable t ) {
LOG.error ( t ) ;
doc.add ( new Chunk ( t.getMessage ( ) ) ) ;
}
}
public static final void appendPDF ( String fileName, Document doc, PdfWriter writer ) throws Exception {
PdfContentByte cb = writer.getDirectContent ( ) ;
PdfReader reader = new PdfReader ( fileName ) ;
int pages = reader.getNumberOfPages ( ) ;
LOG.debug ( "pages: [ { 0 } ] ", new Integer ( pages ) ) ;
for ( int j = 1; j < = pages; j++ ) {
PdfImportedPage page = writer.getImportedPage ( reader, j ) ;
doc.newPage ( ) ;
cb.addTemplate ( page, 0,0 ) ;
System.out.println ( "Added page " + j ) ;
}
}
public static void main ( String [ ] args ) {
try {
Document doc = new Document ( PageSize.A4, 25, 25, 25, 25 ) ;
FileOutputStream out = new FileOutputStream ( "PDFUtil.pdf" ) ;
PdfWriter writer = PdfWriter.getInstance ( doc, out ) ;
doc.open ( ) ;
for ( int i=0 ; i < args.length; i++ ) {
appendAttachment ( args [ i ] , doc, writer ) ;
}
doc.close ( ) ;
}
catch ( Exception e ) {
e.printStackTrace ( ) ;
}
}
}
It working single TIFF image while we r converting TIFF to PDF.but is not working for Multiple Image TIFF images..
protected DataBuffer dataBuffer
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Rectangle getBounds()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public DataBuffer getDataBuffer()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Object getDataElements(int x,
int y,
int w,
int h,
Object outData)
- See Also:
SampleModel.getDataElements(int, int, int, int, Object, DataBuffer)
, ArrayIndexOutOfBoundsException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Object getDataElements(int x,
int y,
Object outData)
- See Also:
SampleModel.getDataElements(int, int, Object, DataBuffer)
, ArrayIndexOutOfBoundsException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public final int getHeight()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public final int getMinX()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public final int getMinY()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public final int getNumBands()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public final int getNumDataElements()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Raster getParent()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public double[] getPixel(int x,
int y,
double[] dArray)
- See Also:
- ArrayIndexOutOfBoundsException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public float[] getPixel(int x,
int y,
float[] fArray)
- See Also:
- ArrayIndexOutOfBoundsException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public int[] getPixel(int x,
int y,
int[] iArray)
- See Also:
- ArrayIndexOutOfBoundsException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public double[] getPixels(int x,
int y,
int w,
int h,
double[] dArray)
- See Also:
- ArrayIndexOutOfBoundsException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[112]_
By Anonymous on 2004/06/14 13:55:08 Rate
getPixels ( 100,100 ) ;
public float[] getPixels(int x,
int y,
int w,
int h,
float[] fArray)
- See Also:
- ArrayIndexOutOfBoundsException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public int[] getPixels(int x,
int y,
int w,
int h,
int[] iArray)
- See Also:
- ArrayIndexOutOfBoundsException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public int getSample(int x,
int y,
int b)
- See Also:
- ArrayIndexOutOfBoundsException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public double getSampleDouble(int x,
int y,
int b)
- See Also:
- ArrayIndexOutOfBoundsException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public float getSampleFloat(int x,
int y,
int b)
- See Also:
- ArrayIndexOutOfBoundsException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[277]Get raster image title
By arpudamary { at } yahoo { dot } com on 2003/06/18 05:48:10 Rate
int xx=yy=0;
int x=5,y=99;
java.awt.image.Raster tile = ( java.awt.image.Raster ) img1.getTile ( xx,yy ) ;
float xyValue1 = tile.getSampleFloat ( x,y,k ) ;
System.out.println ( xyValue1 ) ;
public SampleModel getSampleModel()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public final int getSampleModelTranslateX()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public final int getSampleModelTranslateY()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public double[] getSamples(int x,
int y,
int w,
int h,
int b,
double[] dArray)
- See Also:
- ArrayIndexOutOfBoundsException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public float[] getSamples(int x,
int y,
int w,
int h,
int b,
float[] fArray)
- See Also:
- ArrayIndexOutOfBoundsException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public int[] getSamples(int x,
int y,
int w,
int h,
int b,
int[] iArray)
- See Also:
- ArrayIndexOutOfBoundsException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public final int getTransferType()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public final int getWidth()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
protected int height
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
protected int minX
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
protected int minY
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
protected int numBands
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
protected int numDataElements
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
protected Raster parent
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
protected Raster(SampleModel sampleModel,
DataBuffer dataBuffer,
Point origin)
- See Also:
- NullPointerException, RasterFormatException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
protected Raster(SampleModel sampleModel,
DataBuffer dataBuffer,
Rectangle aRegion,
Point sampleModelTranslate,
Raster parent)
- See Also:
- RasterFormatException, NullPointerException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
protected Raster(SampleModel sampleModel,
Point origin)
- See Also:
- NullPointerException, RasterFormatException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
protected SampleModel sampleModel
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
protected int sampleModelTranslateX
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
protected int sampleModelTranslateY
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
protected int width
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples