首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件开发 >

储存的图片读取为数据流

2012-07-24 
存储的图片读取为数据流 private void btnSelectImage_Click(object sender, EventArgs e){//将需要存储的

存储的图片读取为数据流
 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();
            }
        }

热点排行