ashkan.890
جمعه 01 آذر 1392, 00:18 صبح
سلام
من با استفاده از کد زیر یه عکس رو از دیتا بیس ام فراخونی میکنم تو پیج handler
حالا میخوام عکس تغییر سایز هم پیدا کنه و بعد به خروجی بره
میشه کمکم کنید؟؟
ممنون
public class ImageSlider : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.Clear();
if (!String.IsNullOrEmpty(context.Request.QueryString["id"]))
{
int id = Int32.Parse(context.Request.QueryString["id"]);
Image image = GetImage(id);
context.Response.ContentType = "image/jpeg";
image.Save(context.Response.OutputStream, ImageFormat.Jpeg);
}
else
{
context.Response.ContentType = "text/html";
context.Response.Write("<p>Need a valid id</p>");
}
}
public bool IsReusable
{
get
{
return false;
}
}
private Image GetImage(int id)
{
MemoryStream memoryStream = new MemoryStream();
//Retrieve image from Database to a memeory stream.
// If you are using a different method, use it and assign
// the data to the 'memoryStream' variable.
string connectionString = "Data Source=(local);Initial Catalog=DB1;Integrated Security=True";
using (SqlConnection sqlConnection = new SqlConnection(connectionString))
{
using (SqlCommand sqlCommand = new SqlCommand("SELECT Img FROM Slider WHERE ID = " + id.ToString(), sqlConnection))
{
sqlConnection.Open();
SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
if (sqlDataReader.HasRows)
{
sqlDataReader.Read();
byte[] btImage = (byte[])sqlDataReader["Img"];
memoryStream = new MemoryStream(btImage, false);
}
}
sqlConnection.Close();
}
return Image.FromStream(memoryStream);
}
}
من با استفاده از کد زیر یه عکس رو از دیتا بیس ام فراخونی میکنم تو پیج handler
حالا میخوام عکس تغییر سایز هم پیدا کنه و بعد به خروجی بره
میشه کمکم کنید؟؟
ممنون
public class ImageSlider : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.Clear();
if (!String.IsNullOrEmpty(context.Request.QueryString["id"]))
{
int id = Int32.Parse(context.Request.QueryString["id"]);
Image image = GetImage(id);
context.Response.ContentType = "image/jpeg";
image.Save(context.Response.OutputStream, ImageFormat.Jpeg);
}
else
{
context.Response.ContentType = "text/html";
context.Response.Write("<p>Need a valid id</p>");
}
}
public bool IsReusable
{
get
{
return false;
}
}
private Image GetImage(int id)
{
MemoryStream memoryStream = new MemoryStream();
//Retrieve image from Database to a memeory stream.
// If you are using a different method, use it and assign
// the data to the 'memoryStream' variable.
string connectionString = "Data Source=(local);Initial Catalog=DB1;Integrated Security=True";
using (SqlConnection sqlConnection = new SqlConnection(connectionString))
{
using (SqlCommand sqlCommand = new SqlCommand("SELECT Img FROM Slider WHERE ID = " + id.ToString(), sqlConnection))
{
sqlConnection.Open();
SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
if (sqlDataReader.HasRows)
{
sqlDataReader.Read();
byte[] btImage = (byte[])sqlDataReader["Img"];
memoryStream = new MemoryStream(btImage, false);
}
}
sqlConnection.Close();
}
return Image.FromStream(memoryStream);
}
}