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?
C#
using System;
using System.Configuration;
using System.Web;
using System.IO;
using System.Data;
using System.Data.SqlClient;
publicclassShowImage : IHttpHandler
{
publicvoidProcessRequest(HttpContext context)
{
Int32 empno;
if (context.Request.QueryString["id"] != null)
empno = Convert.ToInt32(context.Request.QueryString["id"]);
elsethrownew ArgumentException("No parameter specified");
context.Response.ContentType = "image/jpeg";
Stream strm = ShowEmpImage(empno);
byte[] buffer = newbyte[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
{
returnnew MemoryStream((byte[])img);
}
catch
{
returnnull;
}
finally
{
connection.Close();
}
}
publicbool IsReusable
{
get
{
returnfalse;
}
}
}
Marvin ReidRank #1,963 · 746 reputationPosted Feb 22, 2022, 11:12 AM EST
+1
You can resize the image to this using the SizeCommand class. Resizing using Resampling will keep a higher quality image, but you can try other modes such as FavorBlack if you are working with black-and-white images. Here is sample code that you can try:
Suthish NairRank #92 · 22.8K reputationPosted Dec 15, 2010, 7:21 AM EST
Joris van Twist12 reputationPosted Dec 15, 2010, 10:09 PM EST
Joris van Twist12 reputationPosted Dec 20, 2010, 11:38 PM EST
Suthish NairRank #92 · 22.8K reputationPosted Dec 22, 2010, 12:38 AM EST
Marvin ReidRank #1,963 · 746 reputationPosted Feb 22, 2022, 11:12 AM EST