How can i convert an array of bitmaps into a brand new image of TIFF format, adding all the bitmaps as frames in this new tiff image?
using .NET 2.0.
Open the JPEG image and click File->Print from the application menu. Choose TIFF Image Printer 11.0 from the list of printers and then click the Print button. Enter the same filename, choose TIFF Multipaged (*. tif) and check Append to file, then click Save.
Yes, a TIFF file can have multiple pages. A multipage TIFF file saves multiple pages as individual image frames. However, mostly the TIFF images are saved one page per file.
TIFF files can store an unlimited number of separate images. Each image has an IFD, or Image File Directory, that records where that image's data and metadata is stored in the file.
A multipage TIFF file is a single TIF file which contains multiple tif images. MTIFF files are a bit like PDF in that they contain multiple pages, but the similarity ends there.
Start with the first bitmap by putting it into an Image object
Bitmap bitmap = (Bitmap)Image.FromFile(file);
Save the bitmap to memory as tiff
MemoryStream byteStream = new MemoryStream(); bitmap.Save(byteStream, ImageFormat.Tiff);
Put Tiff into another Image object
Image tiff = Image.FromStream(byteStream)
Prepare encoders:
var encoderInfo = ImageCodecInfo.GetImageEncoders().First(i => i.MimeType == "image/tiff"); EncoderParameters encoderParams = new EncoderParameters(2); encoderParams.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionNone); encoderParams.Param[1] = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.MultiFrame);
Save to file:
tiff.Save(sOutFilePath, encoderInfo, encoderParams);
For subsequent pages, prepare encoders:
EncoderParameters EncoderParams = new EncoderParameters(2); EncoderParameter SaveEncodeParam = new EncoderParameter( Encoder.SaveFlag, (long)EncoderValue.FrameDimensionPage); EncoderParameter CompressionEncodeParam = new EncoderParameter( Encoder.Compression, (long)EncoderValue.CompressionNone); EncoderParams.Param[0] = CompressionEncodeParam; EncoderParams.Param[1] = SaveEncodeParam; tiff.SaveAdd(/* next image as tiff - do the same as above with memory */, EncoderParams);
Finally flush the file:
EncoderParameter SaveEncodeParam = new EncoderParameter( Encoder.SaveFlag, (long)EncoderValue.Flush); EncoderParams = new EncoderParameters(1); EncoderParams.Param[0] = SaveEncodeParam; tiff.SaveAdd(EncoderParams);
That should get you started.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With