问题
I have a tiff image with two pages. When I convert the file to jpg format I lost second pages. Is there any way to put two images on tiff file into one jpg file. Because of tiff files are too big I have to decrease their sizes. Is there any way to decrease tiff files size programmatically? It could also be a solution to my problem.
回答1:
Since a TIFF can contain multiple frames but JPG can't, you need to convert each single frame into a JPG.
Taken from Windows Dev Center Samples:
public static string[] ConvertTiffToJpeg(string fileName)
{
using (Image imageFile = Image.FromFile(fileName))
{
FrameDimension frameDimensions = new FrameDimension(
imageFile.FrameDimensionsList[0]);
// Gets the number of pages from the tiff image (if multipage)
int frameNum = imageFile.GetFrameCount(frameDimensions);
string[] jpegPaths = new string[frameNum];
for (int frame = 0; frame < frameNum; frame++)
{
// Selects one frame at a time and save as jpeg.
imageFile.SelectActiveFrame(frameDimensions, frame);
using (Bitmap bmp = new Bitmap(imageFile))
{
jpegPaths[frame] = String.Format("{0}\\{1}{2}.jpg",
Path.GetDirectoryName(fileName),
Path.GetFileNameWithoutExtension(fileName),
frame);
bmp.Save(jpegPaths[frame], ImageFormat.Jpeg);
}
}
return jpegPaths;
}
}
回答2:
using System.Drawing;
using System.Drawing.Imaging;
Bitmap bm=Bitmap.FromFile("photo.tif");
bm.Save("photo.jpg",ImageFormat.Jpeg);
回答3:
We faced some problems when converting TIF files to JPEG, because TIF format supports some types of compressions that are not supported in free toolkits. I searched the internet and tried some commercial toolkits, but most of them are hard to implement with many limitations. The toolkit that drew my attention is leadtools, because it supports loading and saving many file formats (including TIF images with different compressions). We used this toolkit convert our images to JPEG format. You can find more information in the following page: http://support.leadtools.com/CS/forums/8925/ShowPost.aspx
Note that you can convert any VB.Net code to C# by using this free code converter: http://www.developerfusion.com/tools/convert/vb-to-csharp/
来源:https://stackoverflow.com/questions/11668945/convert-tiff-to-jpg-format