Hi,

I'm trying to add a jpeg image to an rtf document. First I read in a jpg,
scale it and output it to a ByteArrayOutputStream (using JAI). However, when
I convert this image data to an instance of com.lowagie.text.Image and test
for its type, it doesn't seem to be recongized as a jpeg, but as raw image
data. Does anyone know what is going wrong? I've included some portions of
code:

// IN JAITest class
  public ByteArrayOutputStream writeImageToBuffer( PlanarImage img,
JPEGEncodeParam encodeParam )
  {
    ByteArrayOutputStream out = null;

    try {
      out = new ByteArrayOutputStream();
      ImageEncoder encoder = ImageCodec.createImageEncoder( "JPEG", out,
encodeParam );
      encoder.encode( img );
    } catch (Exception e) { e.printStackTrace(); }

    return out;
  }


// IN RTFTest class
  public void addImage( ByteArrayOutputStream out, int width, int height )
  {
    byte data[] = out.toByteArray();

    try {
      com.lowagie.text.Image img = com.lowagie.text.Image.getInstance(
        width, height, RGB_COMPONENTS, BITS_PER_COMPONENT, data );
      document_.add( img );

      System.out.println( "Is ImgRaw " + String.valueOf(
        img.isImgRaw() ) );
      System.out.println( "Is Jpeg " + String.valueOf(
        img.isJpeg() ) );

      out.close();
    }
    catch ( IOException ie ) { ie.printStackTrace(); }
    catch ( com.lowagie.text.BadElementException be ) {}
    catch ( com.lowagie.text.DocumentException de ) {
de.printStackTrace(); }

  }

// OUTPUT
  Is ImgRaw true
  Is Jpeg false


It might be important to say that if I write the scaled jpeg to a file with
a
FileOutputStream and then create an instance of com.lowagie.text.Image using
this file, it works fine. But if I can skip having to create a new file just
to scale done the image that would be great.

Thanks for any help
Cinzia






-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner.
Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission!
INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to