i want to rotate the image stored inside the database is this possible ? i can get the image from the database i just don't know how to rotate it.
string img = (Request.QueryString["cn"]);
Byte[] bytes = null;
if (rbPhoto1.Checked == true)
{
if (img != null)
{
//string str = "select mem_contenttype, mem_photo from tblCardRequestDetail2 where mem_cardno = '" + Request.QueryString["cn"] + "'";
string str = "select mem_contenttype1, mem_photo1 from tblphotoupload where mem_cardno = '" + img + "'";
SqlCommand cmd = new SqlCommand(str); cmd.Parameters.Add("@1", SqlDbType.VarChar).Value = img;
DataTable dt = GetData(cmd);
bytes = (Byte[])dt.Rows[0]["mem_photo1"];
Response.OutputStream.Write(bytes, 0, bytes.Length);
Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = dt.Rows[0]["mem_contenttype1"].ToString();
Response.AddHeader("content-disposition", "attachment;filename=" + dt.Rows[0]["mem_photo1"].ToString());
Response.BinaryWrite(bytes);
Response.Flush();
//Response.End();
}
}
You can try below code
var memStream = new MemoryStream(bytes);
Image imgFromStream = Image.FromStream(memStream, true);
imgFromStream.RotateFlip(RotateFlipType.Rotate90FlipNone);
imgFromStream.Save(memStream,System.Drawing.Imaging.ImageFormat.Jpeg);//Change to whichever format you need
bytes = imgFromStream.ToArray();
You can use a helper method like this:
public static byte[] ReadRotateAndWriteBitmap(byte[] imageBytes)
{
ImageConverter converter = new ImageConverter();
using (Image img = (Image)converter.ConvertFrom(imageBytes))
{
if (img == null)
return null;
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
return (byte[])converter.ConvertTo(img, typeof(byte[]));
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.