5 .NET框架类在ASP.NET中的使用(2)

1.ASP.NET中实现邮件系统

2.ASP.NET中存取图片到数据库

(1)将图片以二进制存储到数据库

            string pictureUrl ="";
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.InitialDirectory = "d:";
            ofd.RestoreDirectory = true;
            ofd.Filter = "*.jpg|*.jpg|*.bmp|*.bmp";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    pictureUrl = ofd.FileName;//取得图片路径
                    pictureBox1.Image = Image.FromFile(pictureUrl);//将图片显示在pictureBox1控件中
                    FileStream fs = new FileStream(pictureUrl, FileMode.Open, FileAccess.Read);//将图片以文件流的形式进行保存
                    BinaryReader br = new BinaryReader(fs);
                    imgBytesIn = br.ReadBytes((int)fs.Length);
                }
                catch
                {
                    MessageBox.Show("您选择的图片不能被读取或文件类型不对!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    imgBytesIn = null;
                }
            }

(2)将数据库中的以二进制形式保存的图片存入到字节数组中
                try
                {
                    pic=(byte[])(ds.Tables[0].Rows[0]["photo"]);
                    MemoryStream ms = new MemoryStream(pic);//将字节数组存入到二进制流中
                    pictureBox1.Image = Image.FromStream(ms);//二进制流Image控件中显示
                }
                catch
                {
                    pictureBox1.Image = null;
                }

3.用XML传送图片

4.ASP.NET中的图像质量

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值