C# tif文件转jpg


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

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM