/// <summary> /// 縮小裁剪圖片 /// </summary> /// <param name="int_Width">要縮小裁剪圖片寬度</param> /// <param name="int_Height">要縮小裁剪圖片長度</param> /// <param name="input_ImgUrl">要處理圖片路徑</param> /// <param name="out_ImgUrl">處理完畢圖片路徑</param> public void ImgReduceCutOut(int int_Width, int int_Height, string input_ImgUrl, string out_ImgUrl) { // ===上傳標准圖大小=== int int_Standard_Width = 160; int int_Standard_Height = 160; int Reduce_Width = 0; // 縮小的寬度 int Reduce_Height = 0; // 縮小的高度 int CutOut_Width = 0; // 裁剪的寬度 int CutOut_Height = 0; // 裁剪的高度 int level = 100; //縮略圖的質量 1-100的范圍 // ===獲得縮小,裁剪大小=== if (int_Standard_Height * int_Width / int_Standard_Width > int_Height) { Reduce_Width = int_Width; Reduce_Height = int_Standard_Height * int_Width / int_Standard_Width; CutOut_Width = int_Width; CutOut_Height = int_Height; } else if (int_Standard_Height * int_Width / int_Standard_Width < int_Height) { Reduce_Width = int_Standard_Width * int_Height / int_Standard_Height; Reduce_Height = int_Height; CutOut_Width = int_Width; CutOut_Height = int_Height; } else { Reduce_Width = int_Width; Reduce_Height = int_Height; CutOut_Width = int_Width; CutOut_Height = int_Height; } // ===通過連接創建Image對象=== System.Drawing.Image oldimage = System.Drawing.Image.FromFile(Server.MapPath(input_ImgUrl)); // ===縮小圖片=== System.Drawing.Image thumbnailImage = oldimage.GetThumbnailImage(Reduce_Width, Reduce_Height, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero); Bitmap bm = new Bitmap(thumbnailImage); // ===處理JPG質量的函數=== 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); // ===裁剪圖片=== Rectangle cloneRect = new Rectangle(0, 0, CutOut_Width, CutOut_Height); PixelFormat format = bm.PixelFormat; Bitmap cloneBitmap = bm.Clone(cloneRect, format); // ===保存圖片=== cloneBitmap.Save(Server.MapPath(out_ImgUrl), ici, ep); }
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
^異或運算符,位值相同為0,不同為1,見上示例.
//
簡單實際問題舉例:
======\=======\=======
======a=======b=======
上面是2條電路,2個開關分別為a和b,打開狀態:\[1],關閉狀態:/[0].
若同時打開或者關閉,兩條電路均不通.
若a打開[1],b關閉[0],電路1通電
======\=======/=======
若a關閉[0],b打開[1],電路2通電
======/=======\=======
綜上,電路在a,b狀態相同時不通[0],在a,b不同時通電[1].
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
^異或運算符,位值相同為0,不同為1,見上示例.
//
簡單實際問題舉例:
======\=======\=======
======a=======b=======
上面是2條電路,2個開關分別為a和b,打開狀態:\[1],關閉狀態:/[0].
若同時打開或者關閉,兩條電路均不通.
若a打開[1],b關閉[0],電路1通電
======\=======/=======
若a關閉[0],b打開[1],電路2通電
======/=======\=======
綜上,電路在a,b狀態相同時不通[0],在a,b不同時通電[1].