C# tif文件转jpg
生活随笔
收集整理的這篇文章主要介紹了
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);
}
總結
以上是生活随笔為你收集整理的C# tif文件转jpg的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数学--数论--剩余系 与 完全剩余
- 下一篇: Linux中netstat命令怎么用