需要添加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);
}