2014-11-06 97 views
0

截至目前我可以上传我的图像在数据库中的问题是当我旋转图像。 上传的图像不是旋转的,它仍然是我上传的图像,我没有旋转。我怎样才能得到文件中的旋转图像

我怎样才能上传旋转的图像?

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

在哪一点你旋转图像? – grovesNL 2014-11-06 02:54:14

+0

@grovesNL我只需要在任意位置获取旋转图像:) – 20131620 2014-11-06 03:50:24

+0

我不确定你的意思。你想旋转90度吗? 180? 270? – grovesNL 2014-11-06 04:00:05

回答

0

首先确保您的文件保存在磁盘上,然后将文件保存到数据库中。

如果这不会帮助你将可能不得不采取:

  • 旋转得当,旋转可能只由图像浏览器,而不在磁盘上更改图像保存的,我遇到的问题与Picassa中
  • 代码将其旋转(旋转字节)