数据库上传图片及裁剪图片
INSERT
tb(photo)
SELECT
img
FROM
OPENROWSET(BULK
'c:\me.jpg'
,SINGLE_BLOB)
AS
T(img);
裁剪图片
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 /// <summary> 2 /// 压缩图片并居中裁剪 3 /// </summary> 4 /// <param name="imageSource">源图片</param> 5 /// <param name="dHeight">裁剪到高度</param> 6 /// <param name="dWidth">裁剪到宽度</param> 7 /// <returns></returns> 8 public byte[] CropPic(System.Drawing.Image imageSource, int dHeight, int dWidth) 9 { 10 ImageFormat tFormat = imageSource.RawFormat; 11 Bitmap oB = new Bitmap(dWidth, dHeight); 12 Graphics g = Graphics.FromImage(oB); 13 g.Clear(Color.WhiteSmoke); 14 g.CompositingQuality = CompositingQuality.HighQuality; 15 g.SmoothingMode = SmoothingMode.HighQuality; 16 g.InterpolationMode = InterpolationMode.HighQualityBicubic; 17 g.DrawImage(imageSource, new Rectangle(0, 0, dWidth, dHeight), (imageSource.Width - dWidth * imageSource.Height / dHeight) / 2, 0, dWidth * imageSource.Height / dHeight, imageSource.Height, GraphicsUnit.Pixel); 18 MemoryStream stream = new MemoryStream(); 19 oB.Save(stream, ImageFormat.Jpeg); 20 return stream.ToArray(); 21 }