专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > 研发管理

储存的图片读取为数据流

发布时间:2011-06-18 12:18:31 文章来源:www.iduyao.cn 采编人员:星星草
存储的图片读取为数据流
 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();
            }
        }
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: