Hello, I'm currently building an wallpaper website. Therefore I need to have proper-looking thumbnails. The images in the database are 1920x1200, these images need to be properly resized to 384x240.
The following code is what I have so far. But it doesn't resize the image, could anyone implement the code that I need?
<%@ WebHandler Language="C#" Class="ShowImage" %>
using System; using System.Configuration; using System.Web; using System.IO; using System.Data; using System.Data.SqlClient;
public class ShowImage : IHttpHandler { public void ProcessRequest(HttpContext context) { Int32 empno; if (context.Request.QueryString["id"] != null) empno = Convert.ToInt32(context.Request.QueryString["id"]); else throw new ArgumentException("No parameter specified"); context.Response.ContentType = "image/jpeg"; Stream strm = ShowEmpImage(empno); byte[] buffer = new byte[4096]; int byteSeq = strm.Read(buffer, 0, 4096);
while (byteSeq > 0) { context.Response.OutputStream.Write(buffer, 0, byteSeq); byteSeq = strm.Read(buffer, 0, 4096); } //context.Response.BinaryWrite(buffer); }
public Stream ShowEmpImage(int empno) { SqlConnection connection = new SqlConnection(AllPublic.Connstring); string sql = "SELECT Wal1 FROM tbl_cars WHERE modId = @ID"; SqlCommand cmd = new SqlCommand(sql,connection); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@ID", empno); connection.Open(); object img = cmd.ExecuteScalar(); try { return new MemoryStream((byte[])img); } catch { return null; } finally { connection.Close(); } }
public bool IsReusable { get { return false; } }
}
|
And on the asp-page the code looks like this:
img_1.ImageUrl = "~/show/afb1.ashx?id=" + id; img_1.PostBackUrl = "~/show/afb1.ashx?id=" + id;
|
Thanks in advance,
Marvin ReidPosted Feb 22, 2022, 4:12 PM
Suthish NairPosted Dec 22, 2010, 5:38 AM
Joris van TwistPosted Dec 21, 2010, 4:38 AM
Joris van TwistPosted Dec 16, 2010, 3:09 AM
Suthish NairPosted Dec 15, 2010, 12:21 PM