Using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Using system. drawing;
Using system. Drawing. imaging;
Using system. Windows. forms;
Using system. Drawing. drawing2d;
Public partial class _ default: system. Web. UI. Page
{
Private webbrowser _ webbrowser;
Private int width = 495;
Private int width = 221;
Protected void page_load (Object sender, eventargs E)
{
String url = request. querystring ["url"];
_ Webbrowser = new webbrowser ();
_ Webbrowser. scrollbarsenabled = false; // No scroll bar is displayed.
_ Webbrowser. navigate (URL );
_ Webbrowser. documentcompleted + = new webbrowserdocumentcompletedeventhandler (completed );
While (_ webbrowser. readystate! = Webbrowserreadystate. Complete)
{
System. Windows. Forms. application. doevents (); // prevents false positives. If this parameter is removed, the documentcompleted event may not be triggered.
}
}
Public void completed (Object sender, webbrowserdocumentcompletedeventargs E)
{
_ Webbrowser. width = width;
_ Webbrowser. Height = height;
Using (bitmap BMP = new Bitmap (_ webbrowser. Width, _ webbrowser. Height ))
{
_ Webbrowser. drawtobitmap (BMP, new rectangle (0, 0, BMP. Width, BMP. Height ));
Bitmap IMG = kirotate (BMP,-2f, color. White );
System. Io. memorystream MS = new system. Io. memorystream ();
IMG. Save (MS, system. Drawing. imaging. imageformat. GIF );
Response. clearcontent ();
Response. contenttype = "image/GIF ";
Response. binarywrite (Ms. toarray ());
}
}
/// <Summary>
/// Rotate at any angle
/// </Summary>
/// <Param name = "BMP"> original map bitmap </param>
/// <Param name = "angle"> Rotation Angle </param>
/// <Param name = "bkcolor"> background color </param>
/// <Returns> output bitmap </returns>
Public static bitmap kirotate (bitmap BMP, float angle, color bkcolor)
{
Int W = BMP. Width + 2;
Int H = BMP. height + 2;
Pixelformat PF;
If (bkcolor = color. Transparent)
{
PF = pixelformat. format32bppargb;
}
Else
{
PF = BMP. pixelformat;
}
Bitmap TMP = new Bitmap (W, H, Pf );
Graphics G = graphics. fromimage (TMP );
G. Clear (bkcolor );
G. drawimageunscaled (BMP, 1, 1 );
G. Dispose ();
Graphicspath Path = new graphicspath ();
Path. addrectangle (New rectanglef (0f, 0f, W, h ));
Matrix mtrx = new matrix ();
Mtrx. Rotate (angle );
Rectanglef RDBMS = path. getbounds (mtrx );
Bitmap DST = new Bitmap (INT) RDBMS. Width, (INT) RDBMS. Height, Pf );
G = graphics. fromimage (DST );
G. Clear (bkcolor );
G. translatetransform (-RDBMS. X,-RDBMS. y );
G. rotatetransform (angle );
G. interpolationmode = interpolationmode. highqualitybilinear;
G. drawimageunscaled (TMP, 0, 0 );
G. Dispose ();
TMP. Dispose ();
Return DST;
}
}