您的位置:首页 > 数据库

图片更改大小保存至数据库并读取

2013-11-12 11:29 344 查看
//保存图片至数据库
HttpPostedFile upfile = null ;
byte[] bt = null;
if (context.Request.Files.Count > 0)
{
upfile = context.Request.Files[0];
System.Drawing.Image imgOutput = System.Drawing.Bitmap.FromStream(upfile.InputStream);
//修改图片宽度为800,高度等比例缩放
System.Drawing.Image imgOutput2 = imgOutput.GetThumbnailImage(800,imgOutput.Height * 800 / imgOutput.Width, null, IntPtr.Zero);
MemoryStream ms = new MemoryStream();
imgOutput2.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
bt = ms.ToArray();//SQL image类型直接保存
}

//读取

Response.Clear();
Response.ContentType = "image/gif";
Response.BinaryWrite(sqlimg);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: