TIFF File viewer
I want to develop a TIFF file viewer using C# language. I have complete specification of TIFF. Now what all I should read for doing this??
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kip HackmanPosted Nov 2, 2020, 8:43 AM
sds dasdPosted Jul 18, 2013, 10:30 PM
Scott LyslePosted Jun 15, 2008, 12:51 AM
I take it that you are interested in multipage tiffs; this might get you started:
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.IO;
namespace MultiPageTiff
{
public class MultipageTiff
{
public int GetNumberOfPages(string sFileName)
{
//setup the image
Image img = Image.FromFile(sFileName);
//get its guid
Guid ID = img.FrameDimensionsList[0];
//get the frame dimensions
FrameDimension fd = new FrameDimension(ID);
//Gets number of pages
return img.GetFrameCount(fd);
}
public Image GetSpecificPage(string sFileName, int iPageNumber)
{
Image img = Image.FromFile(sFileName);
MemoryStream ms = null;
Image returnImage = Image.FromFile(sFileName);
try
{
ms = new MemoryStream();
Guid ID = img.FrameDimensionsList[0];
FrameDimension fd = new FrameDimension(ID);
img.SelectActiveFrame(fd, iPageNumber);
img.Save(ms, ImageFormat.Bmp);
returnImage = Image.FromStream(ms);
return returnImage;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Error");
return null;
}
finally
{
ms.Close();
}
}
public void SetTIFFCompression(string FileName, double QualityPercentage)
{
//Load a bitmap from file
Bitmap bm = (Bitmap)Image.FromFile(FileName);
//Get the list of available encoders
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
//find the encoder with the image/jpeg mime-type
ImageCodecInfo ici = null;
foreach (ImageCodecInfo codec in codecs)
{
if (codec.MimeType == "image/tiff")
ici = codec;
}
//Create a collection of encoder parameters (we only need one in the collection)
EncoderParameters ep = new EncoderParameters();
//We'll save image with QualityPercentage as compared with the original
//Create an encoder parameter for quality with an appropriate level setting
ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)QualityPercentage);
//Save the image with a filename that indicates the compression quality used
string newFileName = FileName.ToLower().Replace(".tif", "_Quality_" + QualityPercentage + "%.tif");
bm.Save(newFileName, ici, ep);
}
}
}