asp.net - Convert Generic Handler to Server Control -


here have code resizing image fn query string opens image app_data/users , edit logo , resizing low quality , low size image , returns final image.

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))             {                 /* codes can have better image @ 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);                 /* codes can have better image @ final                 gr.drawstring("شهر برفی", new font("tahoma", 10, fontstyle.bold), brushes.white, 10, 42);                 int x1, y1, x2, y2;                 random rg = new random();                 (int = 0; < 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 {     {         return false;     } } } 

my question:

  • how can use code on server control (dll files)?

here have code setting properties our webusercontrols , desktopusercontrols , classes , generic handlers , server controls , webparts , ...

note: code can create property of text in string , shows text in lable (lbl_newstext)

 private string _text;     public string text     {                 {             return _text;         }         set         {             _text = lbl_newstext.text = value;         }     } 

its simple. created new server control , use code. don't have query string there create property that. code can you.

private string _fn; public string fn {         {         return _fn;     }     set     {         _fn = value;     } } 

when control renders use code!

image t = image.fromfile(fn); image t1 = image.fromfile(logodestinationproperty); bitmap b = new bitmap(150, 200 * t.height / t.width); using (graphics gr = graphics.fromimage(b)) {      gr.drawimage(t, 0, 0, 150, 200 * t.height / t.width);     gr.drawimage(t1, 10, 10, t1.width, t1.height);      using (system.io.memorystream memorystream = new system.io.memorystream())     {         b.save(memorystream, imageformat.jpeg);         output.write(context.response.outputstream);     } } 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -