Image.FromFile(@"path\filename.tif")
Image.FromStream(memoryStream)
都產生圖像對象用即使源是一個多幀TIFF文件僅一個幀。 如何加載保留這些幀的圖像文件?使用Image.SaveAdd方法逐幀保存tiff。他們在其他查看器中工作,但.NET Image方法不會加載這些幀,只有第一個。
這是否意味着我沒有辦法從一個方法中返回一個多幀TIFF,在這個方法中我傳入一組要用作幀的位圖?
Image.FromFile(@"path\filename.tif")
Image.FromStream(memoryStream)
都產生圖像對象用即使源是一個多幀TIFF文件僅一個幀。 如何加載保留這些幀的圖像文件?使用Image.SaveAdd方法逐幀保存tiff。他們在其他查看器中工作,但.NET Image方法不會加載這些幀,只有第一個。
這是否意味着我沒有辦法從一個方法中返回一個多幀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;
}
bitmap.Dispose();
For循環後,您需要處理位圖。否則,當您嘗試在其他進程中使用相同的文件時,您會收到錯誤「使用其他進程的文件」。
我能夠通過使用下面的方法來處理多幀tiff。
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();
我還沒有嘗試在.net 2.0中的解決方案,但MSDN顯示類成員存在。它確實解決了我在.net 4.5.2中的問題。
這是否意味着我沒有辦法從一個方法中返回一個多幀TIFF,在這個方法中,我傳入一組要用作幀的位圖集合? – mirezus 2008-12-30 21:38:02