Bitmap instead of streaming tiff image

Hi,
Im reading this post (which is what I want to do):
http://forums.sun.com/thread.jspa?messageID=10557015
Could someone please tell me how the codeshould look like with bitmap instead of streaming the image?
Thanks in advance!

Purge the cache for the offending folder(s) through the Tools menu in Bridge, NOT through the broken global command in Bridge prefs.

Similar Messages

  • A generic error occurred in GDI+ while assing tiff image file to Bitmap and Image

    Hi,
    I am getting "A generic error occurred in GDI+" error while reading the tiff image file to Bitmap or Image.
    Below is my sample code.
    string filePath=@"c:\Images\sample.tif";
    Bitmap bmp=new Bitmap(filePath);   // here getting exception
    int totalpages=bmp.GetFrameCount(.....);
    etc......
    I tried using Bitmap.FromFile() and also from FromStream() even for Image also but there is no use.
    Moreover i m having full permissions for the file path and the tiff file is having multiple pages.
    Can anyone help me to solve this issue please.
    Thanks & Regards,
    Kishore
    Kishore

    Make sure that the Tif file is valid (can other software open it)?  If you are able to save a Tif using GDI+, try saving that Tif, then opening it.  Part of me wonders if there is something about that specific Tif that GDI+ doesn't like.
    You could also try using WIC to open the TIF, perhaps you would have better luck there.

  • How can I merge two TIFF images in one...?

    I need some help please, I am looking for a way to "resize" black & white single TIFF images.
    The process I need to do is like cutting a small image and paste it over a new blank letter-size image (at 300 dpi), like a template.
    Or better yet, is there a way to do something like this...?
    Open image...
    image.*width* = 2550;
    image.*height* = 3300;
    image.save();Some APIs and topics in the internet do or talk about resizing, but the final images get stretched or shrinked and I need them not to do so at all.
    Also, I do not need to display the images, only to get the TIFF images processed and saved back to a file.
    How can I do this with Java and JAI? Unfortunately I am almost new to this and I don't know how difficult it might be to deal with images.

    If 2550 x 3300 isn't the original aspect ratio of the image, then the image is going to looked streched or shrinked in at least one dimension. There is no way around that. It would be like resizing a 2 pixel by 2 pixel image into a 3 pixel by 6 pixel image. The image would look like it's height shrunk or it's width stretched. Had I resized it to 3 pixels by 3 pixels or 6 pixels by 6 pixels, though, then it wouldn't look shrunken or streched.
    Open image...
    image.*width* = 2550;
    image.*height* = 3300;
    image.save();*1)* To open a TIFF image you can use the javax.swing.ImageIO class. It has these static methods
    read(File input)
    read(ImageInputStream stream)
    read(InputStream input)
    read(URL input) You can use which ever method you want. But first you need to install [JAI-ImageIO|https://jai-imageio.dev.java.net/binary-builds.html]. The default ImageReaders that plug themselves into the ImageIO package are BMP, PNG, GIF, and JPEG. JAI-ImageIO will add TIFF, and a few other formats.
    The downside is that if clients want to you use your program on their machine then they to will need to install JAI-ImageIO to read the tiffs. To get around this, you can go to your Java/jdk1.x.x_xx/jre/lib/ext/ folder and copy the jai_imageio.jar file (after you've installed JAI-ImageIO). You can also obtain this jar from any one of the zip files of the [daily builds|https://jai-imageio.dev.java.net/binary-builds.html#Daily_builds]. If you add this jar to your program's classpath and package it together with your program, then clients won't need to install JAI-ImageIO and you'll still be able to read TIFF's. The downside of simply adding the jar to the classpath is that you won't be able to take advantage of a natively accelerated JPEG reader that comes with installing JAI-ImageIO (instead, ImageIO will use the default one).
    *2)* Once you've installed [JAI-ImageIO|https://jai-imageio.dev.java.net/binary-builds.html] and used ImageIO.read(...), you'll have a BufferedImage. To resize it you can do the following
    BufferedImage newImage = new BufferedImage(2550,3300,BufferedImage.TYPE_BYTE_BINARY);
    Graphics2D g = newImage.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.drawImage(oldImage,0,0,2550,3300,null);
    g.dispose();Here, I simply drew the old image (the one returned by ImageIO.read(...)) onto a new BufferedImage object of the appropriate size. Because you said they were black and white TIFF's, I used BufferedImage.TYPE_BYTE_BINARY, which is a black and white image. If you decide to use one the BufferedImage types that support color, then a 2550x3330 image would require at least 25 megabytes to hold into memory. On the other hand, a binary image of that size will only take up about one meg.
    I specified on the graphics object that I wanted Bilinear Interpolation when scaling. The default is Nearest Neighbor interpolation, which while fast, dosen't look very good. Bilinear offers pretty good results scaling both up or down at fast speeds. Bicubic interpolation is the next step up. If you find the resized image to be subpar, then come back and post. There are a couple of other ways to resize an image.
    Note, however, if 2550 x 3300 is not the same aspect ratio as the the TIFF image you loaded, then the resized image will look shrunk or stretched along one dimension. There is absolutely no way around this no matter what resizing technique you use. You'll need an image whose original dimensions are in a 2550/3300 = .772 ratio if you want the resized image to not look like it's streched (you can crop the opened image if you want).
    *3)* Now we save the "newImage" with the same class we read images with: ImageIO . It has these static methods
    write(RenderedImage im, String formatName, File output)
    write(RenderedImage im, String formatName, ImageOutputStream output)
    write(RenderedImage im, String formatName, OutputStream output)You'll suply the resized BufferedImage as the first parameter, "tiff" as the second parameter and an appropriate output for the third parameter. It's pretty much a one line statement to read or write an image. All in all, the whole thing is about 7 lines of code. Not bad of all.
    Now as for the 300 dpi thing, there is a way to set the dpi in the Image's metadata. I'm pretty good at reading an image's metadata, but I've never really tried writing out my own metadata. I know you can set the dpi, and I have a somewhat vague idea how it might be done, but it's not something I've tried before. I think I'll look more into it.

  • Java returning incorrect values for width and height of a Tiff image

    I have some TIFF images (sorry, I cannot post them b/c of there confidential nature) that are returning the incorrect values for the width and height. I am using Image.getWidth(null) and have tried the relevant methods from BufferedImage. When I open the same files in external viewers (Irfanview, MS Office Document Imaging) they look fine and report the "correct" dimensions. When I re-save the files, my code works fine. Obviously, there is something wrong with the files, but why would the Java code fail and not the external viewers? Is there some way I can detect file problems?
    Here is the code, the relevant section is in the print() routine.
    * ImagePrinter.java
    * Created on Feb 27, 2008
    * Created by tso1207
    import java.awt.Graphics2D;
    import java.awt.Image;
    import java.awt.print.PageFormat;
    import java.awt.print.PrinterException;
    import java.io.File;
    import java.io.IOException;
    import java.util.Iterator;
    import javax.imageio.ImageIO;
    import javax.imageio.ImageReader;
    import javax.imageio.stream.FileImageInputStream;
    import javax.imageio.stream.ImageInputStream;
    import com.shelter.io.FileTypeIdentifier;
    public class ImagePrinter extends FilePrintable
       private final ImageReader _reader;
       private final int _pageCount;
       private final boolean _isTiff;
       //for speed we will hold current page info in memory
       private Image _image = null;
       private int _imgWidth = 0;
       private int _imgHeight = 0;
       private int _currentPage = -1;
       public ImagePrinter(File imageFile) throws IOException
          super(imageFile);
          ImageInputStream fis = new FileImageInputStream(getFile());
          Iterator readerIter = ImageIO.getImageReaders(fis);
          ImageReader reader = null;
          while (readerIter.hasNext())
             reader = (ImageReader) readerIter.next();
          reader.setInput(fis);
          _reader = reader;
          int pageCount = 1;
          String mimeType = FileTypeIdentifier.getMimeType(imageFile, true);
          if (mimeType.equalsIgnoreCase("image/tiff"))
             _isTiff = true;
             pageCount = reader.getNumImages(true);
          else
             _isTiff = false;
          _pageCount = pageCount;
       public int print(java.awt.Graphics g, java.awt.print.PageFormat pf, int pageIndex)
          throws java.awt.print.PrinterException
          int drawX = 0, drawY = 0;
          double scaleRatio = 1;
          if (getCurrentPage() != (pageIndex - getPageOffset()))
             try
                setCurrentPage(pageIndex - getPageOffset());
                setImage(_reader.read(getCurrentPage()));
                setImgWidth(getImage().getWidth(null));
                setImgHeight(getImage().getHeight(null));
             catch (IndexOutOfBoundsException e)
                return NO_SUCH_PAGE;
             catch (IOException e)
                throw new PrinterException(e.getLocalizedMessage());
             if (!_isTiff && getImgWidth() > getImgHeight())
                pf.setOrientation(PageFormat.LANDSCAPE);
             else
                pf.setOrientation(PageFormat.PORTRAIT);
          Graphics2D g2 = (Graphics2D) g;
          g2.translate(pf.getImageableX(), pf.getImageableY());
          g2.setClip(0, 0, (int) pf.getImageableWidth(), (int) pf.getImageableHeight());
          scaleRatio =
             (double) ((getImgWidth() > getImgHeight())
                ? (pf.getImageableWidth() / getImgWidth())
                : (pf.getImageableHeight() / getImgHeight()));
          //check the scale ratio to make sure that we will not write something off the page
          if ((getImgWidth() * scaleRatio) > pf.getImageableWidth())
             scaleRatio = (pf.getImageableWidth() / getImgWidth());
          else if ((getImgHeight() * scaleRatio) > pf.getImageableHeight())
             scaleRatio = (pf.getImageableHeight() / getImgHeight());
          int drawWidth = getImgWidth();
          int drawHeight = getImgHeight();
          //center image
          if (scaleRatio < 1)
             drawX = (int) ((pf.getImageableWidth() - (getImgWidth() * scaleRatio)) / 2);
             drawY = (int) ((pf.getImageableHeight() - (getImgHeight() * scaleRatio)) / 2);
             drawWidth = (int) (getImgWidth() * scaleRatio);
             drawHeight = (int) (getImgHeight() * scaleRatio);
          else
             drawX = (int) (pf.getImageableWidth() - getImgWidth()) / 2;
             drawY = (int) (pf.getImageableHeight() - getImgHeight()) / 2;
          g2.drawImage(getImage(), drawX, drawY, drawWidth, drawHeight, null);
          g2.dispose();
          return PAGE_EXISTS;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since version XXX
        * @return
       public int getPageCount()
          return _pageCount;
       public void destroy()
          setImage(null);
          try
             _reader.reset();
             _reader.dispose();
          catch (Exception e)
          System.gc();
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @return
       public Image getImage()
          return _image;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @return
       public int getImgHeight()
          return _imgHeight;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @return
       public int getImgWidth()
          return _imgWidth;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @param image
       public void setImage(Image image)
          _image = image;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @param i
       public void setImgHeight(int i)
          _imgHeight = i;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @param i
       public void setImgWidth(int i)
          _imgWidth = i;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @return
       public int getCurrentPage()
          return _currentPage;
        * <br><br>
        * Created By: TSO1207 - John Loyd
        * @since Mar 25, 2008
        * @param i
       public void setCurrentPage(int i)
          _currentPage = i;
    }Edited by: jloyd01 on Jul 3, 2008 8:26 AM

    Figured it out. The files have a different vertical and horizontal resolutions. In this case the horizontal resolution is 200 DPI and the vertical is 100 DPI. The imgage width and height values are based on those resolution values. I wrote a section of code to take care of the problem (at least for TIFF 6.0)
       private void setPageSize(int pageNum) throws IOException
          IIOMetadata imageMetadata = _reader.getImageMetadata(pageNum);
          //Get the IFD (Image File Directory) which is the root of all the tags
          //for this image. From here we can get all the tags in the image.
          TIFFDirectory ifd = TIFFDirectory.createFromMetadata(imageMetadata);
          double xPixles = ifd.getTIFFField(256).getAsDouble(0);
          double yPixles = ifd.getTIFFField(257).getAsDouble(0);
          double xRes = ifd.getTIFFField(282).getAsDouble(0);
          double yres = ifd.getTIFFField(283).getAsDouble(0);
          int resUnits = ifd.getTIFFField(296).getAsInt(0);
          double imageWidth = xPixles / xRes;
          double imageHeight = yPixles / yres;
          //if units are in CM convert ot inches
          if (resUnits == 3)
             imageWidth = imageWidth * 0.3937;
             imageHeight = imageHeight * 0.3937;
          //convert to pixles in 72 DPI
          imageWidth = imageWidth * 72;
          imageHeight = imageHeight * 72;
          setImgWidth((int) Math.round(imageWidth));
          setImgHeight((int) Math.round(imageHeight));
          setImgAspectRatio(imageWidth / imageHeight);
       }

  • Trying to display multipage tiff image getting error

    Hi
    I am trying to read multipage tiff image but dont know how
    I tried to display single page tiff getting error
    my code is
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Drawing;
    using System.Drawing.Imaging;
    namespace Documentviewer1
        public partial class _Default : System.Web.UI.Page
            //string filepath = "";
            protected void Page_Load(object sender, EventArgs e)
                //// filepath = "image\045237302.tif";
                string appath = Server.MapPath("/image") + @"\";
                string imagename = Request.QueryString["ImageFileName"];
                string filename = appath + imagename;
                Response.ContentType = "image/tiff";
                new Bitmap(filename).Save(Response.OutputStream, ImageFormat.Tiff);
                ////System.Drawing.Image TheImg = new App.Files.TIF(Request.QueryString["FilePath"]).GetTiffImageThumb(System.Convert.ToInt16(Request.QueryString["Pg"]), System.Convert.ToInt16(Request.QueryString["Height"]),
    System.Convert.ToInt16(Request.QueryString["Width"]));//getting error in thisline Parameter not valid
    my aspx page is has
    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
        CodeBehind="Default.aspx.cs" Inherits="Documentviewer1._Default" %>
    <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    </asp:Content>
    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
        <h2>
          <img alt="" src ="image/045237302.tif" width="200" height="200"/>
        </h2>
        <p>
            To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>.
        </p>
        <p>
            You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&amp;clcid=0x409"
                title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
        </p>
    </asp:Content>
    getting error as Parameter not valid.
    Can anybody help me to display the image in the browser.
    Thanks
    Mary Abraham
    Mary Sunish

    Hi MaryAbraham,
    Since the issue regards ASP.NET and website deployment. I suggestion you post the question in the ASP.NET forums at
    http://forums.asp.net/. It is appropriate and more experts will assist you.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to retain the same resolution while croping a tiff image using jai api

    Hi all,
    I have designed a program to crop a tiff image.But after croping the tiff,the resultant file resolution is not the same as the original source file.
    In the program,the source file Nadeshiko_v1_02.tif has the resolution(X) of 1200 DPI and resolution(Y) has 1200 DPI pixels.
    But after croping the resolution of output file is 100 DPI.
    Please give me some idea on how to retain the same resolution.
    <code>
    package jai;
    import java.awt.Frame;
    import java.awt.image.RenderedImage;
    import java.awt.image.renderable.ParameterBlock;
    import java.awt.image.renderable.RenderableImage;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import javax.imageio.*;
    import javax.imageio.stream.ImageOutputStream;
    import javax.media.jai.Interpolation;
    import javax.media.*;
    import javax.media.jai.JAI;
    import javax.media.jai.PlanarImage;
    import javax.media.jai.RenderedOp;
    import javax.media.jai.widget.ScrollingImagePanel;
    import com.sun.media.jai.codec.FileSeekableStream;
    import com.sun.media.jai.codec.SeekableStream;
    import com.sun.media.jai.codec.TIFFEncodeParam;
    import javax.media.jai.OperationDescriptorImpl;
    import java.io.*;
    import java.util.Iterator;
    import javax.media.jai.operator.*;
    // import javax.media.jai.widget.ScrollingImagePanel;
    public class crop {
              /** The main method. */
    public static void main(String[] args) {
    /* Validate input. */
    /* if (args.length != 1) {
    System.out.println("Usage: java JAISampleProgram " +
    "input_image_filename");
    // System.exit(-1);
    float a=(float) 70.3;
    float b=(float) 70.4;
    float c=(float) 3100.3;
    float d=(float) 5522.4;
    * Create an input stream from the specified file name
    * to be used with the file decoding operator.
    String TIFF="TIFF";
    FileSeekableStream stream = null;
    try {
         stream = new FileSeekableStream("D:\\tif images\\Nadeshiko_v1_02.tif");
    // stream = new FileSeekableStream("D:\\tif images\\Nadeshiko_v1_01.jpg");
    } catch (IOException e) {
    e.printStackTrace();
    System.exit(0);
    // Load the source image from a Stream.
    RenderedImage im = JAI.create("stream", stream);
    RenderedImage image2= CropDescriptor.create(im, a, b, c, d, null);
    ScrollingImagePanel panel = new ScrollingImagePanel(image2, 100, 100);
    // Create a frame to contain the panel.
    Frame window = new Frame("JAI Image Cropping");
    window.add(panel);
    window.pack();
    // window.show();
    // Define the source and destination file names.
    // String inputFile = "D:\\tif images\\Nadeshiko_v1_05.tif";
    String outputFile = "D:\\tif images\\Nadeshiko_v1_04.tif";
    // Save the image on a file. We cannot just store it, we must set the image encoding parameters
    // to ensure that it will be stored as a tiled image.
    TIFFEncodeParam tep = new TIFFEncodeParam();
    tep.setWriteTiled(true);
    tep.setTileSize(80,80);
    JAI.create("filestore",image2,outputFile,"TIFF",null);
    try {
                   stream.close();
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
    </code>
    Thanks,
    Sanat Meher

    Try the following,
    TIFFEncodeParam tep = new TIFFEncodeParam();
    // Create {X,Y}Resolution fields.
    TIFFField fieldXRes = new TIFFField(0x11A, TIFFField.TIFF_RATIONAL,
                                        1, new long[][] {{DPI_X, 1}});
    TIFFField fieldYRes = new TIFFField(0x11B, TIFFField.TIFF_RATIONAL,
                                        1, new long[][] {{DPI_Y, 1}});
    tep.setExtraFields(new TIFFField[] {fieldXRes, fieldYRes});

  • How to edit 16bit TIFF image sequence file in FCP?

    Dear all,
    I have a number of 16 bit TIFF image sequence files (2048 x 1024 resolution) - some of them are RED footage, and others came directly from our f/x guy. We are going into a color correction session in a post house and we've been asked to provide a sequential 16 bit TIFF image sequence of the edited time line.
    I need to do a cross dissolve b/w most of the clips I have. I have created image sequence QT movie (reference files) from the TIFF images. Though they play fine in QT player, when I try importing into FCP, I am met with a "general error". I tried both dragging it into QT, as well as File --> Import.
    I am wondering what can I do to get these clips into FCP in order to apply the cross dissolve transitions I need. Is this a problem relating to the 16bit nature of the TIFF files?
    I tried exporting the TIFF image sequence standalone QT movie, and those imported fine. However, I have a feeling that the standalone movie conversion also decrease my bit depth from 16 to 8. (When I do my final TIFF output from FCP after dissolves / transitions had been applied, each TIFF file is now 8 MB instead of 12 MB, hence my suspicion that the bit depth is adjusted).
    Are there any settings I am missing, or does FCP simply don't support 16 bit image sequence reference file. As a test, I had also converted all my TIFF to jpg, and created jpeg image sequence reference file. These reference QT file can be successfully imported to FCP and I can edit them as if they are a clip.
    If FCP is not able to handle these files, what are my other options? After Effects?
    Any help is appreciated.
    Thank you.
    Michael
    <Edited by Moderator>

    As far as I know, both FCP and Color only support up to 10 bit color, which is 1024 levels for each color channel, more than enough for avoiding color banding.
    If you need 16 bit for sure, I believe AE will support 16 bit output. Another 16 bit application would be the extended version of Photoshop, which has some limited time line capability.

  • Editing metadata in a TIFF image

    Hi everyone,
    I'm trying to edit TIFF image metadata using ImageIO v1.1 APIs, but something goes wrong...
    For a TIFFImageWriter I get the following results:
    writer.canInsertEmpty = true
    writer.canInsertImage = true
    writer.canRemoveImage = false
    writer.canReplaceImageMetadata = false
    writer.canReplacePixels = true
    writer.canReplaceStreamMetadata = false
    writer.canWriteEmpty = true
    writer.canWriteRasters = false
    writer.canWriteSequence = trueSo editing metadata with writer.replaceImageMetadata is not possible (I verified this, an exception is thrown). I thought I could remove an entire image and reinsert it with new metadata, but as you can see writer.removeImage is unavailable, too.
    How can I edit a TIFF image without rewriting it to a totally new image file?
    Any help will be appreciated,
    Giuseppe

    Huh... I am in bitmap... OK, how would I go about changing to RGB? Not a complete novice, but never had a similar problem before.

  • Tiff images in smartforms

    Hello firends,
    Can we use TIFF images in Smartforms instead of BMAP.
    Presently we are using BMAP Graphics.
    If it is possible, please provide the solution.
    regards.
    vamshi

    Hi Vamshi,
    Refer this wiki follow the steps uploading the tiff image in se78 and then include the graphics in the smart forms by creating the graphic node and display.
    https://www.sdn.sap.com/irj/scn/wiki?path=/display/abap/uploading%252blogo%252bin%252bscript
    Regards,
    Sravanthi

  • Displaying a tiff image in a browser.

    Hi I need to display a tiff image in the browser which does not have a tiff plugin. I guess I have to convert the tiff to jpeg on the fly and write it in the output stream. Has anyone worked on this or knows any other way. Please not I dont want to create an intermediate jpeg file.

    Thanks for your help. I am having one problem though. The tiff file is not being read. The ImageIO.read(file); is returning null. I guess I am using the wrong ImageIO class.( javax.imageio.ImageIO;). I am pasting the code below. See if you can find out the bug.
    package tiffToJpg;
    import java.awt.image.BufferedImage;
    import java.io.ByteArrayOutputStream;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import javax.servlet.GenericServlet;
    import javax.servlet.ServletException;
    import javax.servlet.ServletOutputStream;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    import com.sun.image.codec.jpeg.JPEGCodec;
    import com.sun.image.codec.jpeg.JPEGImageEncoder;
    * @author Deepak_Mulchandani
    * TODO To change the template for this generated type comment go to
    * Window - Preferences - Java - Code Style - Code Templates
    public class TiffToJpg extends GenericServlet
         public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException
              File file=new File("Demo1.jpg");
         ServletOutputStream servletOuputStream=response.getOutputStream();
                        BufferedImage image = ImageIO.read(file);
                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
              JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(baos);
                        encoder.encode(image);
                   servletOuputStream.write(baos.toByteArray());
    }

  • Displaying Tiff Image on browser

    Hi friends ,
    I want to display tiff image on browser . For that i have written one servlet witch will desplay tiff image on browser
    Here i am sending my code snippets for servlet.
    Here file is source file which i want to display.
    FileSeekableStream ss = new FileSeekableStream(file);
              ImageDecoder tiffDecoder= ImageCodec.createImageDecoder("tiff", ss, null);;
              p = tiffDecoder.getNumPages();
              for(int x=0;x<p;x++){
              RenderedImage tiffPage = tiffDecoder.decodeAsRenderedImage(x);
              ByteArrayOutputStream stream = new ByteArrayOutputStream();
         TIFFEncodeParam tiffOptions = new TIFFEncodeParam();
         // You may want to set compression or tile attributes on the     EncodeParam here
         RenderedOp l_return = JAI.create("encode", tiffPage, stream,"TIFF", tiffOptions);
         bt = stream.toByteArray();
    then writing this byte array(bt)
    OutputStream out;
    out.write(bt);
    and responce .setContentType("image/tiff");
    i also want to know whether mime type image/tiff is supported or not in servlet.
    When i run servlet i am getting File Downloading dialog box.
    also when i download image file it's size is very large than original.
    Plz correct my code.It's verry urgent.
    Thanks in Advance

    hi, could you post the solution?
    I'm looking forward to know the solution.
    Thanks

  • Reading TIFF image in YcbCr photometric interpretation

    Hi,
    Can anyone tell me what needs to be modified in the following code snippet to read a TIFF image having the YcbCr photometric interpretation.
    File file = new FILE(filename)
    SeekableStream stream = new FileSeekableStream(file);
    ImageDecoder decoder = imageCodec.createImageDecoder("tiff",s,null);
    RenderedImage image = dec.decodeAsrenderedImage();
    ScrollingImagePanel panel = new ScrollingImagePanel( image,image.getWidth(),image.getHeight());
    The following code reads the image but assumes RGB photometric interpretation.
    Any info will be helpful.
    Thanks,
    Panna

    try this:
    File file = new FILE(filename)
    SeekableStream stream = new FileSeekableStream(file);
    //add these lines
    TIFFDecodeParam tiffparam = new TIFFDecodeParam();
    tiffparam.setJPEGDecompressYCbCrToRGB( false );
    //change the following line
    ImageDecoder decoder = imageCodec.createImageDecoder("tiff",s,tiffparam);
    RenderedImage image = dec.decodeAsrenderedImage();
    ScrollingImagePanel panel = new ScrollingImagePanel( image,image.getWidth(),image.getHeight());
    hope this helps!

  • Color Handling when saving Word document as PDF, containing CMYK TIFF image?

    What is the proper procedure for creating PDFs from Word documents that contain a CMYK TIFF image? I have created a company logo by exporting an AI file with Pantone colors as a TIFF (with a CMYK color profile, since there is the intention of printing). Since it is a logo, color consistency is important and the utmost priority. I will be needing to insert this file into a Word document that will then be converted into a PDF.
    I've read somewhere that Word automatically converts images to RGB, and also have come across potential problems of colors being changed in the final PDF through unmanaged color handling and conversions. I figured instead of running around in circles trying to find the best solution, I'd post on here. Is this procedure possible? What is the best way to do this without changing my original color profile or CMYK values of the logo being used?
    This PDF has the intention of being placed online for offices to print/publish.
    Thanks!

    Though actually, let's take a step back -- why do you want to use CMYK? Most offices won't be using PostScript printers, so the CMYK will be converted to RGB for printing. For publishing - do you know the required CMYK profile to use for all possible publishing scenarios? Properly tagged RGB is generally considered the way to deal with this in modern workflows not targeted at a specific press. But still probably not with Word!

  • Open Tiff image failed with imageio package

    I'm trying to open tiff files with javax.imageio.ImageReader. When openning the image file, "bad.TIF" with the following codes, I got an error. However, I can open the image with "Windows Picture and Fax Viewer" (WPFV). After I opened/saved as File "good.TIF" with WPFX, I can open the image with the progarm. Would someone please help? Thanks.
    Error position is 2
    java.lang.ArrayIndexOutOfBoundsException: 2012
         at com.sun.media.imageioimpl.plugins.tiff.TIFFFaxDecompressor.nextNBits(TIFFFaxDecompressor.java:1503)
         at com.sun.media.imageioimpl.plugins.tiff.TIFFFaxDecompressor.decodeNextScanline(TIFFFaxDecompressor.java:792)
         at com.sun.media.imageioimpl.plugins.tiff.TIFFFaxDecompressor.decodeT4(TIFFFaxDecompressor.java:1040)
         at com.sun.media.imageioimpl.plugins.tiff.TIFFFaxDecompressor.decodeRaw(TIFFFaxDecompressor.java:677)
         at com.sun.media.imageio.plugins.tiff.TIFFDecompressor.decode(TIFFDecompressor.java:2514)
         at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.decodeTile(TIFFImageReader.java:1137)
         at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.read(TIFFImageReader.java:1417)
         at javax.imageio.ImageReader.readAll(ImageReader.java:1050)
         at com.rxamerica.image.LoadTiff.main(LoadTiff.java:35)
    import java.io.File;
    import java.io.IOException;
    import java.util.Iterator;
    import javax.imageio.IIOImage;
    import javax.imageio.ImageIO;
    import javax.imageio.ImageReader;
    import javax.imageio.stream.ImageInputStream;
    public class LoadTiff {
    public static void main(String[] args)
    String myDir = "./";
    String testFile1 = myDir + "good.TIF";
    String testFile2 = myDir + "bad.TIF";
    int errorPos = 0;
    ImageInputStream tiffStream = null;
    ImageReader reader;
    try {
    reader = getReader("TIFF");
    IIOImage tiffImage = null;
    errorPos = 1;
    File file = new File(testFile1);
    tiffStream = ImageIO.createImageInputStream(file);
    reader.setInput(tiffStream);
    tiffImage = reader.readAll(0, reader.getDefaultReadParam());
    errorPos = 2;
    file = new File(testFile2);
    tiffStream = ImageIO.createImageInputStream(file);
    reader.setInput(tiffStream);
    tiffImage = reader.readAll(0, reader.getDefaultReadParam());
    catch (Exception e) {
    System.out.println("Error position is " + errorPos);
    e.printStackTrace();
    public static ImageReader getReader(String suffix) throws IOException {
    Iterator readers = ImageIO.getImageReadersBySuffix(suffix);
    if (readers.hasNext())
    return (ImageReader) readers.next();
    else
    throw new IOException("No readers for suffix: " + suffix);
    }

    Can you upload the bad tiff to an [image hosting site|http://www.imagehosting.com/]?
    In general, when you set the input stream on a reader for a second time, it's a good idea to call reset.
    errorPos = 2;
    file = new File(testFile2);
    tiffStream = ImageIO.createImageInputStream(file);
    reader.reset();  <----- this line
    reader.setInput(tiffStream);
    tiffImage = reader.readAll(0, reader.getDefaultReadParam());I don't think that's the source of your problems though. You can add an IIOReadUpdateListener and a IIOReadWarningListener to the reader to see just how far it gets just before the exception is thrown. It may very well just be a badly saved tiff, or it could be a tiff image reader bug.
    Edited by: Maxideon on Jan 19, 2009 7:07 PM
    BTW, which version of JAI-ImageIO are you using?

  • Print Multi-page TIff images

    Hi,
    I have multipage tiff images. I am loading the image in the jScrollPane. I also have NEXT Button which
    show the next image of the tiff file in the JscrollPane. Right now i have a PRINT button which prints the
    image that's in the jscrollpane. I want to do something which prints the all the images in that tiff file.
    Instead of the image that's in the jScrollpane. If you need the code please let me know.
    Any help is always appreciated.
    Thanks.

    can send me the code so that I will see...
    thanks
    kumar
    [email protected]

Maybe you are looking for