C# 如何在.NET 2.0中打开多帧TIFF imageformat图像?
或 即使源文件是多帧TIFF文件,两者都只生成一帧的图像对象如何加载保留这些帧的图像文件?使用image.SaveAdd方法逐帧保存TIFF。它们在其他查看器中工作,但.NET图像方法不会加载这些帧,只加载第一帧C# 如何在.NET 2.0中打开多帧TIFF imageformat图像?,c#,tiff,system.drawing,C#,Tiff,System.drawing,或 即使源文件是多帧TIFF文件,两者都只生成一帧的图像对象如何加载保留这些帧的图像文件?使用image.SaveAdd方法逐帧保存TIFF。它们在其他查看器中工作,但.NET图像方法不会加载这些帧,只加载第一帧 这是否意味着无法从我传递位图集合以用作帧的方法返回多帧TIFF?以下是我使用的方法: Image.FromStream(memoryStream) 私有列表GetAllPages(字符串文件) { 列表图像=新列表(); 位图位图=(位图)Image.FromFile(文件); in
这是否意味着无法从我传递位图集合以用作帧的方法返回多帧TIFF?以下是我使用的方法:
Image.FromStream(memoryStream)
私有列表GetAllPages(字符串文件)
{
列表图像=新列表();
位图位图=(位图)Image.FromFile(文件);
int count=bitmap.GetFrameCount(FrameDimension.Page);
for(int idx=0;idx
位图.Dispose()
在For循环之后,您需要处理位图。否则,当您尝试在其他进程中使用相同的文件时,会出现错误“文件使用其他进程”。我能够使用以下方法处理多帧tiff
private List<Image> GetAllPages(string file)
{
List<Image> images = new List<Image>();
Bitmap bitmap = (Bitmap)Image.FromFile(file);
int count = bitmap.GetFrameCount(FrameDimension.Page);
for (int idx = 0; idx < count; idx++)
{
// save each frame to a bytestream
bitmap.SelectActiveFrame(FrameDimension.Page, idx);
MemoryStream byteStream = new MemoryStream();
bitmap.Save(byteStream, ImageFormat.Tiff);
// and then create a new Image from it
images.Add(Image.FromStream(byteStream));
}
return images;
}
Image multiImage=Image.FromFile(sourceFile);
multiImage.Save(目标文件、tiff、婴儿车);
int pageCount=multiImage.GetFrameCount(FrameDimension.Page);
对于(int page=1;page
我还没有在.NET2.0中尝试过该解决方案,但MSDN显示了类成员的存在。它确实解决了我在.net 4.5.2中遇到的问题。这是否意味着,如果我传入一组位图作为帧使用,则无法从该方法返回多帧TIFF?是的,您必须记住,在多帧TIFF中,每个帧都可以有自己的一组编码选项(压缩、颜色、质量)。另一方面,位图是更简单的动物。什么是dupImage?
private List<Image> GetAllPages(string file)
{
List<Image> images = new List<Image>();
Bitmap bitmap = (Bitmap)Image.FromFile(file);
int count = bitmap.GetFrameCount(FrameDimension.Page);
for (int idx = 0; idx < count; idx++)
{
// save each frame to a bytestream
bitmap.SelectActiveFrame(FrameDimension.Page, idx);
MemoryStream byteStream = new MemoryStream();
bitmap.Save(byteStream, ImageFormat.Tiff);
// and then create a new Image from it
images.Add(Image.FromStream(byteStream));
}
return images;
}
Image multiImage = Image.FromFile(sourceFile);
multiImage.Save(destinationFile, tiff, prams);
int pageCount = multiImage.GetFrameCount(FrameDimension.Page);
for (int page = 1; page < pageCount; page++ )
{
multiImage.SelectActiveFrame(FrameDimension.Page,page);
multiImage.SaveAdd(dupImage,prams);
}
multiImage.SaveAdd(newPage, prams);
multiImage.Dispose();