需要添加WindowBase,PresentationCore的引用。
代碼如下:
private Stream GetImageStream()
{
//可以通過網絡或本地文件的形式,返回Tif文件流
}
Stream stream = GetImageStream()
string fileName = "temp.jpg";//需要保存的文件名
using(FileStream fs = new FileStream(fileName,FileMode.Create)
{
TiffBitmapDecoder decoder = new TiffBitmapDecoder(stream,BitmapCreateOptions.PreservePixelFormat,BitmapCacheOption.Default);
BitmapSource bitmapSource = decoder.Frames[0];//此處只取tiff中的第一幀,可以根據情況取多幀,從Frames.Count中取
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmapSource);
encoder.Save(fs);
}
