ASP. C # Image Processing

Source: Internet
Author: User

Add an Image control to the ASPX page, which imageurl= "image.aspx", adding a image.aspx that is specifically designed to working with Images, write the following code in the Page_Load event handling in CS code:
Original image
String physicalpath = Server.MapPath ("./129519.jpg");
System.Drawing.Image Srcbitmap = Bitmap.fromfile (PhysicalPath);
Desired target Image
int outheight = Srcbitmap.height * 2;
int outwidth = Srcbitmap.width * 2;
First, create a blank bitmap
Bitmap Outbitmap = new Bitmap (Outwidth, Outheight, Pixelformat.format24bpprgb);
Graphics g = graphics.fromimage (Outbitmap);
Drawing on the Outbitmap
Rectangle destrectangle=new Rectangle (0, 0, outwidth, outheight);
int SRCX = 0;
int Srcy = 0;
G.drawimage (Srcbitmap, destrectangle/* shows the size of the image */, srcx,srcy/* from this x, Y coordinates to intercept the */,srcbitmap.width/4/* intercept width */, srcbitmap.height/4/* Interception High */, GraphicsUnit.Pixel);

Setting the output type
Response.ContentType = "Image/jpeg";
Output to Client
Outbitmap.save (Response.outputstream, imageformat.jpeg);
Response.End ();

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.