Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Tuesday, April 12, 2011 11:57:04 AM(UTC)
kdbolt70

Groups: Registered
Posts: 1


I have a multipage TIFF I create on the fly, which needs to be broken up into two page TIFFs and serialized to a MemoryStream. In addition, I am converting the compression from LZW to Group IV. I am using .NET 3.5 with LeadTools version 17.0.

Perhaps I'm making this more difficult than it should be, but I'm not sure the best way to do it. Here's whats I currently have:

                RasterCodecs codecs = new RasterCodecs();
                CodecsImageInfo info = codecs.GetInformation( file, true );
                RasterImage image = codecs.Load( file, 0, CodecsLoadByteOrder.RgbOrGray, currentPage, currentPage + (detail.Pages - 1) );
               Image newImage = RasterImageConverter.ConvertToImage( image, ConvertToImageOptions.None );
               MemoryStream memStream = new MemoryStream();
                  newImage.Save( memStream, System.Drawing.Imaging.ImageFormat.Tiff );

               ImageCodecInfo encoderInfo = GetEncoderInfo(  );

                  EncoderParameters encoderParams = new EncoderParameters( 2 );
                  EncoderParameter parameter = new EncoderParameter( System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionCCITT4 ); //change compression
                  encoderParams.Param[0] = parameter;
                  EncoderParameter param2 = new EncoderParameter( System.Drawing.Imaging.Encoder.SaveFlag, (long)EncoderValue.MultiFrame );
                  encoderParams.Param[1] = param2;
                  newImage.Save(memStream, encoderInfo , encoderParams); //save first page to stream

                  if (detail.Pages == 2)
                  {
                     encoderParams.Param[1] = new EncoderParameter( System.Drawing.Imaging.Encoder.SaveFlag, (long)EncoderValue.FrameDimensionPage );
                     image.Page = 2; //move image to the next page
                     newImage.SaveAdd( RasterImageConverter.ConvertToImage( image, ConvertToImageOptions.None ), encoderParams );

                     encoderParams.Param[1] = new EncoderParameter( System.Drawing.Imaging.Encoder.SaveFlag, (long)EncoderValue.Flush );
                     newImage.SaveAdd( encoderParams );

                  }
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Wednesday, April 13, 2011 12:58:42 AM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,326

Was thanked: 1 time(s) in 1 post(s)

All you need is:
1. Load the image using RasterCodecs.Load(
   string fileName,
   int bitsPerPixel,
   CodecsLoadByteOrder order,
   int firstPage,
   int lastPage)

2. Save the image using RasterCodecs.Save(
   RasterImage image,
   string fileName,
   RasterImageFormat.CcittGroup4,
   1,
   int firstPage,
   int lastPage,
   int firstSavePageNumber,
   CodecsSavePageMode pageMode)

You can either use the CodecsSavePageMode.Overwrite to create new file (Overwrite the entire file), or CodecsSavePageMode.Append Append the page to the end of the file.

You don't need to worry about any encoder objects.

Thanks,
Maen Badwan
LEADTOOLS Technical Support
 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.768 seconds.