How to open a multi-frame TIFF imageformat image in .NET 2.0?

前端 未结 3 1089
猫巷女王i
猫巷女王i 2020-12-08 11:53
Image.FromFile(@\"path\\filename.tif\")

or

Image.FromStream(memoryStream)

both produce image objects with only on

3条回答
  •  感动是毒
    2020-12-08 12:21

    Here's what I use:

    private List GetAllPages(string file)
    {
        List images = new List();
        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;
    }
    

提交回复
热议问题