c# 图片路径转byte[] 插到数据库BLOB 图片长宽自定义

时间:2024-07-09 08:04:01

//根据图片路径读取图片并且转byte[]   类型

                    FileStream fs = new FileStream(filePath, FileMode.Open);
byte[] byData = new byte[fs.Length];
fs.Read(byData, 0, byData.Length);
fs.Close();

//根据图片路径读取图片修改长宽 并且转byte[]   类型

            var pic = new Bitmap(filePath);
Bitmap newpic = new Bitmap((System.Drawing.Image)pic);
var savepic = new Bitmap(newpic, 100, 120);
MemoryStream ms = new MemoryStream();
savepic.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] byData = ms.GetBuffer();
ms.Close();

//byte[] 插入到数据库

http://www.cnblogs.com/wdw31210/p/3937417.html