代码改变世界

c#用picturebox显示多页TIF

2013-07-05 19:36  假面Wilson  阅读(1680)  评论(0编辑  收藏  举报
//引用
using System.Drawing;
using System.Drawing.Imaging;

//以下是方法
private Bitmap myImage = null;
private Byte[] Faxbyte = null;
private FrameDimension fds;

memStream = new MemoryStream(Faxbyte);
myImage = new Bitmap(memStream);

                #region 分页
                Guid gud = (Guid)myImage.FrameDimensionsList.GetValue(0);
                fds = new FrameDimension(gud);
                int totalPage = myImage.GetFrameCount(fds);

//多页用combobox切换
                if (totalPage > 0)
                {
                    for (int i = 1; i <= totalPage; i++)
                    {
                        cboPages.Items.Add(new ListItems(i.ToString(), i.ToString()));
                    }

                    myImage.SelectActiveFrame(fds, 0);
                    FaxImage.Image = myImage;
                    FaxImage.SizeMode = PictureBoxSizeMode.AutoSize;
                    cboPages.Text="1";
                }
                #endregion


//Combobox 切换事件
        private void cboPages_SelectionChangeCommitted(object sender, EventArgs e)
        {
            myImage.SelectActiveFrame(fds, Convert.ToInt32(cboPages.Text) - 1);
            FaxImage.Image = myImage;
        }