ASP. NET

Source: Internet
Author: User

 

Using System;
Using System. Web;
Using System. drawing;
Using System. Drawing. imaging;
Using System. net;
Using System. IO;

Namespace Goodspeed. Test. httphandle
{

Public   Class Myjpg: ihttphandler
{
Public Myjpg () {}

Public   Void Processrequest (httpcontext context)
{
Httpresponse response = Context. response;
Httprequest request = Context. request;
String URL = Request. url. tostring ();
// Url =" Http://www.allinone.net.cn/office/photo/pic/20040714/ "+ URL. substring (URL. lastindexof ("/") + 1 );
URL =   " Http://img1.qq.com/news/20040721/490452.jpg " ;

Response. contenttype =   " Image/JPEG " ;

WebClient WC =   New WebClient ();
Stream resstream = WC. openread (URL );
Image originalimage = Image. fromstream (resstream ); // Get Image

Method 2 # RegionMethod 2
//Byte [] mydatabuffer = WC. downloaddata (URL );
//Response. binarywrite (mydatabuffer );
# Endregion

Watermark # Region Watermark
Image newimage = Image. fromfile ( " C: \ watermark1.gif " );
// Watermark
Using (Graphics g = Graphics. fromimage (originalimage ))
{
Point ulcorner =   New Point (originalimage. Width - Newimage. Width -   5 , Originalimage. Height - Newimage. Height -   5 ); // Watermark position
G. drawimage (newimage, ulcorner );
G. Dispose ();
}

# Endregion

Originalimage. Save (response. outputstream, imageformat. JPEG );
Response. End ();
Originalimage. Dispose ();
WC. Dispose ();
}

Public   Bool Isreusable
{
Get {Return True;}
}

}
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.