在这里,我有一个用于从fn查询字符串调整图像大小的代码,该字符串从App_Data/Users打开图像并使用我的徽标对其进行编辑,并将其调整为低质量和低尺寸图像并返回最终图像。
using System;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
public class UsersImageThumb : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
{
try
{
Image t = Image.FromFile(context.Server.MapPath("~/App_Data/Users/") + context.Request["fn"]);
Image t1 = Image.FromFile(context.Server.MapPath("~/favicon.png"));
Bitmap b = new Bitmap(150, 200 * t.Height / t.Width);
using (Graphics gr = Graphics.FromImage(b))
{
/* Some codes that can help us to have better image at final
gr.CompositingQuality = CompositingQuality.HighSpeed;
gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
gr.CompositingMode = CompositingMode.SourceCopy;
*/
gr.DrawImage(t, 0, 0, 150, 200 * t.Height / t.Width);
gr.DrawImage(t1, 10, 10, t1.Width, t1.Height);
/* Some codes that can help us to have better image at final
gr.DrawString("شهر برفی", new Font("Tahoma", 10, FontStyle.Bold), Brushes.White, 10, 42);
int x1, y1, x2, y2;
Random rg = new Random();
for (int i = 0; i < 100; i++)
{
x1 = rg.Next(0, 250);
x2 = rg.Next(0, 250);
y1 = rg.Next(0, 250 * t.Height / t.Width);
y2 = rg.Next(0, 250 * t.Height / t.Width);
gr.DrawLine(Pens.White, x1, y1, x2, y2);
}
*/
using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
{
b.Save(memoryStream, ImageFormat.Jpeg);
memoryStream.WriteTo(context.Response.OutputStream);
}
}
}
catch
{
context.Response.Write("Image Not Found");
}
}
}
public bool IsReusable {
get {
return false;
}
}
}
我的问题:
- 如何在服务器控制(DLL 文件)上使用此代码?
在这里,我们有一个代码用于设置WebUserControls、DesktopUserControls、Classes、Generic Handlers、Server Controls、WebParts和...
注意:此代码可以在 String 中创建 Text 的属性并在标签 ( lbl_NewsText
)中显示 Text
private string _Text;
public string Text
{
get
{
return _Text;
}
set
{
_Text = lbl_NewsText.Text = value;
}
}