³Ð½ÓÒÔÇ°µÄ×é¼þϵÁУ¬Õâ¸ö×é¼þϵÁÐÖ¼ÔÚ½éÉÜ.NETÏà¹ØµÄ×é¼þ£¬Èôó¼Ò¿ÉÒÔÔÚÏîÄ¿ÖÐÓÐÒ»¸ö¸üºÃµÄÑ¡Ôñ£¬ÉçÇø¶ÔÓÚµÚÈý·½²å¼þµÄ½éÉÜ»¹ÊDZȽÏÉٵģ¬ºÜ¶à²©ÎĵÄÄÚÈÝÖ÷Òª»¹ÊǽéÉÜһЩ¼òµ¥µÄ²Ù×÷£¨ºÜ¶àÈ˶¼Ëµ²©¿ÍÔ°ÏÖÔÚÊÇ“hello world”µÄˮƽ£¬²©ÎÄÖÊÁ¿ÔÚϽµ£¬¶ÔÓÚÕâһ˵·¨£¬ÎÒ¾õµÃÕâ¸ö˵·¨ÓÐЩ¹ýÍ·ÁË£¬¿ÉÄÜһЩ²©ÎĵÄȷдµÄ±È½Ï³õ¼¶£¬µ«ÊǺܶ಩ÎĵÄÉîÈ뻹ÊDZȽϴó£¬Ö»ÊǺÜÉÙÊÜÈ˹Ø×¢£©£¬Õâ¸ö×é¼þϵÁÐÖ÷ÒªÔÚ½éÉÜһЩ¹¦ÄܵÄ×é¼þ£¬¸½´ø¸Ã×é¼þµÄºËÐĶÔÏó½éÉÜ¡£
×é¼þµÄ½éÉܾø¶Ô²»ÊÇһƪÎÄÕ¿ÉÒÔÐðÊöÍêµÄ£¬ÒòΪһ¸ö×é¼þÊǾ¹ý¿ª·¢Õߺܳ¤ÖÜÆڵĿª·¢£¬¾ø²»ÊÇÎÒÕâÀïһƪ¼òµ¥µÄ²©ÎľͿÉÒÔ½éÉÜÍê±ÏµÄ£¬×é¼þ½éÉܵÄϵÁУ¬Ò»°ã»áÑØÏ®×Å×é¼þ±³¾°½éÉÜ¡¢×é¼þʹÓýéÉÜ¡¢ºËÐĶÔÏó½éÉܵȵÈÄÚÈÝ¡£Èç¹û¶Ô×é¼þ¸ÐÐËȤ£¬¿ÉÒÔÉîÈëµÄÁ˽âºÍѧϰ¡£
·Ï»°ÉÙ˵£¬½øÈëÕýÌâ¡£
ÎÒÃÇÔÚÏîÄ¿Öкܶàʱºò¶¼»á¶ÔÎļþ½øÐд¦Àí£¬ÀýÈçÎļþµÄÉÏ´«ÏÂÔصȵȡ£ÆäÖжÔͼƬµÄʵʱ²Ù×÷Ò²»á½Ï¶à£¬ÔÚÕâÀï½éÉÜÒ»¿îÓÃC££±àдµÄÇáÁ¿¼¶¿âµÄ¼¯ºÏ£¬ËüÔÊÐíÄãʹÓÃ.NET 4.5+À´¶¯Ì¬µØ´¦ÀíͼÏñµÄ×é¼þ£¬ÄǾÍÊÇImageProcessor£¬ÓÃÓÚͼÏñµÄ¼´Ê±´¦ÀíµÄ.NET¿â¡££¨×éÖ¯µÄ¿ªÔ´ÏîÄ¿×飬»á¾¹ýµÚÒ»¸öÏîÄ¿µÄÄ¥ºÏºó£¬µÚ¶þÏîÄ¿»á¿ª·¢Ò»¸ö.NET Core×é¼þ£©
Ò».ImageProcessor×é¼þ¸ÅÊöImageProcessorÊÇÓÃC££±àдµÄÇáÁ¿¼¶¿âµÄ¼¯ºÏ£¬ËüÔÊÐíÄãʹÓÃ.NET 4.5+À´¶¯Ì¬µØ´¦ÀíͼÏñ£¬°üÀ¨Á½¸öÖ÷¿âImageProcessor£¨ÓÃÓÚ×ÀÃæºÍÓ¦ÓóÌÐòʹÓã©ImageProcessor.Web£¨ASP.NET¹¹½¨µÄ¶¯Ì¬Í¼Ïñ´¦ÀíÀ©Õ¹£©£¬¸Ã×é¼þ¿ìËÙ£¬¿ÉÀ©Õ¹£¬Ò×ÓÚʹÓã¬À¦°óÁËһЩºÜÇ¿´óµÄ¹¦ÄÜ£¬¶øÇÒÊÇÍêÈ«¿ªÔ´¡£¸Ã×é¼þÓÐÁ½¸ö²¿·Ö£¬ÎÒÃǽñÌ콫Ö÷Òª½²½âImageProcessor²¿·ÖµÄÄÚÈÝ£¬Èç¹û¶ÔÁíÍâÒ»¸ö¸ÐÐËȤ£¬¿ÉÒÔ×ÔÐÐÁ˽⡣
ImageProcessor.WebÏòÏîÄ¿Ìí¼ÓÁËÒ»¸ö¿ÉÅäÖõÄHttpModule£¬ÔÊÐí¶ÔͼÏñÎļþ½øÐм´Ê±´¦Àí¡£¸ÃÄ£¿é»¹ÌṩÁËÒ»¸ö»ùÓÚÎļþºÍä¯ÀÀÆ÷µÄ»º´æ£¬¿ÉÒÔ´¦ÀíÊý°ÙÍòµÄͼÏñ£¬Ôö¼Ó´¦ÀíÊä³öºÍ½ÚÊ¡±¦¹óµÄ·þÎñÆ÷ÄÚ´æ¡£¸Ã×é¼þµÄ¹¦ÄÜ·½·¨°üÀ¨£ºµ÷Õû´óС£¬Ðýת£¬Ô²½Ç£¬·×ª£¬²Ã¼ô£¬Ë®Ó¡£¬¹ýÂËÆ÷£¬±¥ºÍ¶È£¬ÁÁ¶È£¬¶Ô±È¶È£¬ÖÊÁ¿£¬¸ñʽ£¬Ð¡²åÇú£¬¸ß˹ģºý£¬¸ß˹Èñ»¯ºÍ͸Ã÷¶È¡£
ImageProcessor.WebµÄµ±Ç°°æ±¾ÊÇ4.8.2£¬¿ÉÒÔÏÂÔØÔ´ÂëºÍDLLÎļþ£¨±¾È˽¨Òé×îºÃÏÂÔØÔ´Â룬ºÃ´¦¾Í²»ÔÚÕâÀï׸Êö£©¡£
°²×°ImageProcessor.Webʱ£¬Ä¬ÈÏÇé¿öÏ£¬Web.configÖÐÌí¼ÓÅäÖýڵ㣬ÈçϽڵ㡣
<add name=type=/></httpModules>
ÕâÔÊÐí¿âImageProcessingModuleÀ¹½Ø±¾µØͼÏñ´¦ÀíÇëÇó¡£ImageProcessor.WebÊǸ߶ȿÉÅäÖõġ£¿ÉÒÔ½«ÆäËûÅäÖÃÎļþÌí¼Óµ½½â¾ö·½°¸ÖУ¬ÒÔ±ã´Ó¶à¸öÀ´Ô´¼ìË÷£¬´¦ÀíºÍ»º´æͼÏñ¡£¶ÔÓÚ¸Ã×é¼þµÄÅäÖÃÉèÖÿÉÒԲ鿴Îĵµ¡£
¶þ.ImageProcessor×é¼þ²Ù×÷¸ÅÊö½éÉÜÁË×é¼þµÄÏà¹ØÐÅÏ¢£¬ÔÚÕâÀï½éÉÜһϸÃ×é¼þµÄ²Ù×÷ʵÀý¡£ImageFactoryÀàÌṩÁ˶Ըø¶¨Í¼ÏñÖ´Ðи÷ÖÖ²Ù×÷¹¦Äܵķ½·¨¡£Ëü¾¹ý¾«ÐÄÉè¼ÆÒÔ·ÀÖ¹ÔÚÒÔ¸ßÐÔÄÜ·½Ê½´¦ÀíͼÏñʱͨ³£·¢ÉúµÄ¸÷ÖÖÄÚ´æй©¡£ÕâʹÆä¿ÉÒÔ°²È«µØÔÚ×ÀÃæºÍWeb»·¾³ÖÐʹÓá£ImageFactory×Ô¶¯¼ì²â¸ø¶¨Í¼ÏñµÄÕýÈ·ÎļþÀàÐÍ£¬²¢ÇÒ¸ÃÀàµÄAPIÊÇÁ÷³©µÄ£¬ÕâÔÊÐíÄúÇáËɵØÁ´½Ó·½·¨ÒÔÌṩËùÐèµÄÊä³ö¡£ÀýÈ磬ÒÔÏ´úÂë¼ÓÔØ£¬µ÷Õû´óС£¬ÉèÖÃиñʽ²¢±£´æ°üº¬Í¼ÏñÐÅÏ¢µÄMemoryStream¡£
Image(string file) { if (string.IsNullOrEmpty(file)) { throw new ArgumentNullException(file); } byte[] photoBytes = System.IO.File.ReadAllBytes(file); // ¼ì²â¸ñʽ ISupportedImageFormat format = new JpegFormat { Quality = 70 }; Size size = new Size(150, 0); using (MemoryStream inStream = new MemoryStream(photoBytes)) { using (MemoryStream outStream = new MemoryStream()) { (ImageFactory imageFactory = new ImageFactory(true)) { // ¼ÓÔØ£¬µ÷Õû´óС£¬ÉèÖøñʽºÍÖÊÁ¿²¢±£´æͼÏñ¡£ imageFactory.Load(inStream) .Resize(size) .Format(format) .Save(outStream); //¶Ô»ñÈ¡µÄimageFactory¶ÔÏó½øÐжÔÓ¦µÄ²Ù×÷ } //¶Ô»ñÈ¡µÄÊý¾ÝÁ÷½øÐвÙ×÷ } }
¶ÔÓÚͼƬµÄ²Ù×÷£¬¾ßÌåÓн϶àµÄ²Ù×÷·½Ê½£¬¾ßÌåµÄ·½·¨ÓÐÈçϵķ½·¨£º
·½·¨Ãû³Æ ·½·¨²Ù×÷˵Ã÷
Reset ½«µ±Ç°Í¼ÏñÖØÖÃΪÆäÔʼ¼ÓÔØ״̬
Alpha ¸ü¸Äµ±Ç°Í¼ÏñµÄ²»Í¸Ã÷¶È
AutoRotate Ö´ÐÐ×Ô¶¯ÐýתÒÔÈ·±£·´Ó³EXIF¶¨ÒåµÄÐýת×îÖÕͼÏñ
BitDepth ¸Ä±äµ±Ç°Í¼ÏñµÄλÉî¶È
Brightness ¸ü¸Äµ±Ç°Í¼ÏñµÄÁÁ¶È
BackgroundColor ¸ü¸Äµ±Ç°Í¼ÏñµÄ±³¾°ÑÕÉ«
Constrain Ô¼Êøµ±Ç°Í¼Ïñ£¬µ÷ÕûÆä´óСÒÔÊʺϸø¶¨µÄ³ß´ç£¬Í¬Ê±±£³ÖÆä×ݺá±È
Contrast ¸ü¸Äµ±Ç°Í¼ÏñµÄ¶Ô±È¶È
Crop ½«µ±Ç°Í¼Ïñ²Ã¼ôµ½¸ø¶¨µÄλÖúʹóС
DetectEdges ¼ì²âµ±Ç°Í¼ÏñÖеıßÔµ
Resolution ÉèÖÃͼÏñµÄ·Ö±æÂÊ
EntropyCrop ½«Í¼ÏñÐÞ¼ôµ½×î´óìصÄÇøÓò
Filter ½«¹ýÂËÆ÷Ó¦ÓÃÓÚµ±Ç°Í¼Ïñ
Flip ˮƽ»ò´¹Ö±·×ªµ±Ç°Í¼Ïñ
Gamma µ÷Õû¸ø¶¨Í¼ÏñµÄ»Ò¶È£¨¹âÇ¿¶È£©·ÖÁ¿
GaussianBlur ʹÓøß˹ÄÚºËÄ£ºýµ±Ç°Í¼Ïñ
Hue ¸Ä±äµ±Ç°Í¼ÏñµÄÉ«µ÷£¬¸Ä±äÕûÌåÑÕÉ«
Halftone ½«µ±Ç°Í¼Ïñת»»Îª¸ÃͼÏñµÄCMYK°ëÉ«µ÷±íʾ
Quality ¸Ä±äµ±Ç°Í¼ÏñµÄÊä³öÖÊÁ¿
ReplaceColor Ìæ»»µ±Ç°Í¼ÏñÖеÄÑÕÉ«
Resize ½«µ±Ç°Í¼Ïñµ÷ÕûΪ¸ø¶¨³ß´ç
Rotate ½«µ±Ç°Í¼ÏñÐýת¸ø¶¨½Ç¶È
ÒÔÉÏÖ»ÊÇÁгöÁËһЩÖ÷ÒªµÄ²Ù×÷·½·¨£¬»¹ÓÐÆäËûµÄ·½·¨ÕâÀï¾Í²»ÔÙ½éÉÜ£¬ÓÐÐËȤ¿ÉÒÔ×Ô¼ºÈ¡Êµ¼ù¡£ÏÂÃæ¾Í½éÉÜÒ»ÏÂһЩºËÐĶÔÏó¡£
Èý.ImageProcessorºËÐĶÔÏó½âÎö½âÎöÀ´ÎÒÃǾßÌåÁ˽âһϺËÐĵķ½·¨ºÍÊôÐÔ£¬¿´¿´Ô´Â뻹ÊÇÓкô¦¡£
1.ImageFactory.Load()
¡¡