我正在尝试将图像文件夹中的图像和图像名称defaultImage
转换为我的数据库表。
但是现在我在这行代码中遇到了问题:
我使用以下代码更改代码:
Image uploaded6 = Image.FromFile("/image/defaultImage.jpg");
而不是这个:
System.Drawing.Image uploaded = System.Drawing.Image.FromStream(
〜/图像/默认图像);
我现在得到的错误FileNotFoundException was unhandled by user code
我已经使用文件上传控件尝试过这种方法,它工作正常,但不知道如何转换文件夹中的图像。
如何从文件夹中获取图像以便使用下面显示的方法进行转换。
Image uploaded6 = Image.FromFile("/image/defaultImage.jpg");
//System.Drawing.Image uploaded = System.Drawing.Image.FromStream();
System.Drawing.Image newImage = new Bitmap(1024, 768);
using (Graphics g = Graphics.FromImage(newImage))
{
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(uploaded, 0, 0, 1024, 768);
}
byte[] results;
using (MemoryStream ms = new MemoryStream())
{
ImageCodecInfo codec = ImageCodecInfo.GetImageEncoders().FirstOrDefault(c => c.FormatID == ImageFormat.Jpeg.Guid);
EncoderParameters jpegParms = new EncoderParameters(1);
jpegParms.Param[0] = new EncoderParameter(Encoder.Quality, 95L);
newImage.Save(ms, codec, jpegParms);
results = ms.ToArray();
}
string sqlImage = "update MemberReport set image1 = @Data where memberreportid = '" + Session["memberreportid"] + "'";
SqlCommand cmdImage = new SqlCommand(sqlImage);
cmdImage.Parameters.AddWithValue("@Data", results);
InsertUpdateData(cmdImage);