程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> 存儲的圖片讀取為數據流

存儲的圖片讀取為數據流

編輯:C#入門知識

private void btnSelectImage_Click(object sender, EventArgs e)
        {
            //將需要存儲的圖片讀取為數據流
            openFileDialog1.Filter = "*jpg|*jpg|*bmp|*bmp";
            if (DialogResult.OK == openFileDialog1.ShowDialog())
            {


                foreach (string file in openFileDialog1.FileNames)
                {
                    FileStream fsBLOBFile = new FileStream(file, FileMode.Open, FileAccess.Read);
                    byte[] bytBLOBData = new byte[fsBLOBFile.Length];
                    buffer = new byte[fsBLOBFile.Length];
                    fsBLOBFile.Read(bytBLOBData, 0, bytBLOBData.Length);
                    fsBLOBFile.Close();
                    buffer = bytBLOBData;
                }
            }
        }


        void ShowImage(byte[] imagecode)
        {
            if (imagecode != null)
            {
                MemoryStream stmBLOBData = new MemoryStream(imagecode);
                System.Drawing.Image bmp = System.Drawing.Image.FromStream(stmBLOBData);
                Rectangle rc = pictureBox1.ClientRectangle;
                SizeF size = new SizeF(bmp.Width / bmp.HorizontalResolution, bmp.Height / bmp.VerticalResolution);
                float fScale = Math.Min(rc.Width / size.Width, rc.Height / size.Height);
                size.Width *= fScale;
                size.Height *= fScale;
                pictureBox1.Image = new Bitmap(bmp, size.ToSize());
                this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
                stmBLOBData.Close();
            }
        }


作者:chinaboykai

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved