我有减少图像大小的代码,但我不明白如何将该图像保存到sql server数据库中,如果你有关于那个的逻辑那么请给我。 下面是我的服务器端代码,
HttpPostedFileBase pphoto;
string filename = Path.GetFileName(pphoto.FileName);
string targetPath = Server.MapPath("Images/" + filename);
Stream strm = pphoto.InputStream;
var targetFile = targetPath;
//Based on scalefactor image size will vary
/*generate thumbnales*/
using (var image = Image.FromStream(strm))
{
var newWidth = (int)(image.Width * 0.5);
var newHeight = (int)(image.Height *0.5);
var thumbnailImg = new Bitmap(newWidth, newHeight);
var thumbGraph = Graphics.FromImage(thumbnailImg);
var thumbGraph = Graphics.FromImage(thumbnailImg);
thumbGraph.CompositingQuality =CompositingQuality.HighQuality;
thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
var imageRectangle = new Rectangle(0, 0,newWidth, newHeight);
thumbGraph.DrawImage(image, imageRectangle);
thumbnailImg.Save(targetPath, image.RawFormat);
}