截至目前,我可以在数据库中上传我的图像,当我旋转图像时出现问题。 上传的图像不是旋转的图像,它仍然是我上传的图像,我没有旋转。
如何上传旋转的图像?
Stream FileStream = File.OpenRead(ServerPath + Filename);
// Stream FileStream = FileUpload1.PostedFile.InputStream;
// System.Drawing.Image.FromFile(ServerPath + Filename);
//System.Drawing.Bitmap postedimage = new System.Drawing.Bitmap(FileStream);
objImage = ScaleImage(PostedImage, 73);
if (FileType != "jpg" && FileType != "JPG")
{
objImage.Save(ServerPath + jpgFileName, ImageFormat.Jpeg);
}
else
{
//objImage.Save(ServerPath + Filename);
}
img = new byte[FileStream.Length];
contentlength = FileStream.Length;
if (contentlength > 506000)
{
ClientScript.RegisterClientScriptBlock(typeof(Page), "ClosePopup", "File is to large! Maximum size is 8kb", true);
}
else if (contentlength <= 506000)
{
//ImageConverter converter = new ImageConverter();
//byte[] bytestr = (byte[])converter.ConvertTo(objImage, typeof(byte[]));
//fs.InputStream.Read(img, 0, fs.ContentLength);
byte[] bytestr = null;
var fsm = ToStream(objImage, ImageFormat.Jpeg);
//Stream fsm = ScaleImage(objImage, 73);
BinaryReader br = new BinaryReader(fsm);
bytestr = br.ReadBytes((int)fsm.Length);
SqlCommand cmd = new SqlCommand("Select * FROM tblphotoupload where mem_cardno = '" + sParameter + "'", connection);
SqlDataReader alinan_veri3;
alinan_veri3 = cmd.ExecuteReader();
if (alinan_veri3.Read())
{
int sct = 2;
int a = Convert.ToInt32(alinan_veri3["upload_count"]);
if (sct == 2)
{
if (a >= 2) a = 2;
sql = "update tblphotoupload set mem_photo" + Convert.ToString(a + 1) + " = @img, upload_date" + Convert.ToString(a + 1) + " = '" + sDateTime + "', mem_contenttype" + Convert.ToString(a + 1) + " = '" + FileType + "', mem_photofile" + Convert.ToString(a + 1) + " = '" + Filename + "', upload_count='" + (a + 1) + "' where mem_cardno = '" + sParameter + "'";
connection.Close();
SqlConnection connection2 = new SqlConnection(ConfigurationManager.ConnectionStrings["EKConn"].ConnectionString);
connection2.Open();
SqlCommand cmd2 = new SqlCommand(sql, connection2);
cmd2.Parameters.Add(new SqlParameter("@img", bytestr));
cmd2.ExecuteNonQuery();
connection2.Close();
}
}
else
{
//string ole;
sql = "insert into tblphotoupload (mem_cardno, mem_photo1, upload_date1, upload_count, mem_contenttype1, mem_photofile1) values ('" + sParameter + "', @img, '" + sDateTime + "','1','" + FileType + "','" + Filename + "')";
connection.Close();
SqlConnection connection2 = new SqlConnection(ConfigurationManager.ConnectionStrings["EKConn"].ConnectionString);
connection2.Open();
SqlCommand cmd2 = new SqlCommand(sql, connection2);
cmd2.Parameters.Add(new SqlParameter("@img", bytestr));
cmd2.ExecuteNonQuery();
connection2.Close();
}
}
}
答案 0 :(得分:0)
首先确保您的文件保存在磁盘上,然后将文件保存到DB中。
如果这无济于事,您可能需要: