C # image cropping code,

Source: Internet
Author: User

C # image cropping code,

/// <Summary> /// scale down the cropped image /// </summary> /// <param name = "int_Width"> scale down the cropped image width </param>/ // <param name = "int_Height"> length of the cropped image </param> // <param name = "input_ImgUrl"> path of the image to be processed </param> // /<param name = "out_ImgUrl"> processed image path </param> public void ImgReduceCutOut (int int_Width, int int_Height, string input_ImgUrl, string out_ImgUrl) {// === upload standard image size === int int_Standard_Width = 160; int int_Standard_Height = 160; int performance_width = 0; // The reduced width int Reduce_Height = 0; // The Reduced Height int CutOut_Width = 0; // The cropped width int CutOut_Height = 0; // The cropped height int level = 100; // The range of the quality of the thumbnail from 1 to ///== get zoom out, crop size = if (int_Standard_Height * int_Width/int_Standard_Width> int_Height) {performance_width = int_Width; performance_height = optional * int_Width/height; CutOut_Width = int_Width; CutOut_Height = int_Height;} else if (optional * int_Width/width <int_Height) {performance_width = optional * int_Height/int_standarheight d_height; performance_height = int_Height; CutOut_Width = int_Width; CutOut_Height = int_Height;} else {performance_width = int_Width; performance_height = int_Height; Height = int_Width; CutOut_Height = int_Height ;} // === create an Image object through a connection === System. drawing. image oldimage = System. drawing. image. fromFile (Server. mapPath (input_ImgUrl); // === zoom out image === System. drawing. image thumbnailImage = oldimage. getThumbnailImage (performance_width, performance_height, new System. drawing. image. getThumbnailImageAbort (ThumbnailCallback), IntPtr. zero); Bitmap bm = new Bitmap (thumbnailImage); // === function for processing JPG quality === ImageCodecInfo [] codecs = ImageCodecInfo. getImageEncoders (); ImageCodecInfo ici = null; foreach (ImageCodecInfo codec in codecs) {if (codec. mimeType = "image/jpeg") ici = codec;} EncoderParameters ep = new EncoderParameters (); ep. param [0] = new EncoderParameter (Encoder. quality, (long) level); // bm. save (Server. mapPath ("2.jpg"), ici, ep); // === crop an image === Rectangle cloneRect = new Rectangle (0, 0, CutOut_Width, CutOut_Height ); pixelFormat format = bm. pixelFormat; Bitmap cloneBitmap = bm. clone (cloneRect, format); // ===save the image === cloneBitmap. save (Server. mapPath (out_ImgUrl), ici, ep );}

 


C language ^ how to use

A1 = 0x01; // 0000 0001
A2 = 0x00; // 0000 0000
A3 = 0x03; // 0000 0011
A4 = 0x02; // 0000 0010

B1 = a1 ^ a2; // 0000 0001
B2 = a1 ^ a3; // 0000 0010
B3 = a1 ^ a4; // 0000 0011

^ XOR operator. The bitwise value is 0 and the difference is 1. See the example above.

//
Examples of simple and practical problems:
====================================
======= A ======= B =========
There are two circuits on the top. The two switches are a and B respectively. The opening status is \ [1], and the closing status is/[0].
If both circuits are enabled or disabled.
If a turns on [1], B turns off [0], and circuit 1 Powers on
=====================
If a disables [0], B enables [1], and circuit 2 powers on.
====================================
In summary, the circuit fails in the and B states simultaneously [0]. When a and B are different, the power is charged [1].

C language ^ how to use

A1 = 0x01; // 0000 0001
A2 = 0x00; // 0000 0000
A3 = 0x03; // 0000 0011
A4 = 0x02; // 0000 0010

B1 = a1 ^ a2; // 0000 0001
B2 = a1 ^ a3; // 0000 0010
B3 = a1 ^ a4; // 0000 0011

^ XOR operator. The bitwise value is 0 and the difference is 1. See the example above.

//
Examples of simple and practical problems:
====================================
======= A ======= B =========
There are two circuits on the top. The two switches are a and B respectively. The opening status is \ [1], and the closing status is/[0].
If both circuits are enabled or disabled.
If a turns on [1], B turns off [0], and circuit 1 Powers on
=====================
If a disables [0], B enables [1], and circuit 2 powers on.
====================================
In summary, the circuit fails in the and B states simultaneously [0]. When a and B are different, the power is charged [1].

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.