当前位置: 首页 > 编程语言 > C#

从多个页面中提取帧tiff-c#分享

时间:2023-04-10 19:37:47 C#

从多个页面中提取帧tiff-c#有一个多页tiff,我想从这个Tiff文件中提取page[n]/frame[n]和保存。如果我的多页tiff有3个帧,在我提取一页/帧后-我想留下1张图像,2页/帧和1张图像,只有1页/帧。下面是将多帧tiff中的最后一帧保存到单页tiff文件的一些代码。(为了使用此代码,您需要添加对PresentationCore.dll的引用)。以上就是C#学习教程:从多个页面中提取帧tiff-c#分享的全部内容,如果对大家有用还需要进一步了解C#学习教程,希望大家多加关注—StreamimageStreamSource=新的FileStream(图像文件名,FileMode.Open,FileAccess.Read,FileShare.Read);内存流memstream=new内存流();memstream.SetLength(imageStreamSource.Length);imageStreamSource.Read(memstream.GetBuffer(),0,(int)imageStreamSource.Length);imageStreamSource.Close();BitmapDecoder解码器=TiffBitmapDecoder.Create(memstream,BitmapCreateOptions.PreservePixelFormat,BitmapCacheOption.Default);Int32frameCount=decoder.Frames.Count;BitmapFrameimageFrame=decoder.Frames[0];MemoryStream输出=new)TiffBitmapEncoder编码器=newTiffBitmapEncoder();encoder.Frames.Add(imageFrame);编码器。保存(输出);FileStreamoutStream=File.OpenWrite("Image.Tiff");output.WriteTo(outStream);outStream.Flush();outStream.Close();输出.冲洗();输出.关闭();publicvoidSaveFrame(字符串路径,intframeIndex,stringtoPath){using(FileStreamstream=newFileStream(path,FileMode.Open,FileAccess.Read,FileShare.Read)){BitmapDecoderdec=BitmapDecoder.Create(stream,BitmapCreateOptions.IgnoreImageCache,BitmapCacheOption.None);BitmapEncoderenc=BitmapEncoder.Create(dec.CodecInfo.ContainerFormat);enc.Frames.Add(dec.Frames[frameIndex]);使用(FileStreamtmpStream=newFileStream(toPath,FileMode.Create)){enc.Save(tmpStream);}}}本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如有转载请注明出处: