﻿
{"id":2380,"date":"2013-12-05T09:17:24","date_gmt":"2013-12-05T09:17:24","guid":{"rendered":"http:\/\/www.gencayyildiz.com\/blog\/?p=2380"},"modified":"2013-12-05T09:17:24","modified_gmt":"2013-12-05T09:17:24","slug":"c-ile-resim-kapasitesini-ayarlama","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/c-ile-resim-kapasitesini-ayarlama\/","title":{"rendered":"C# \u0130le Resim Kapasitesini Ayarlama"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p><a href=\"http:\/\/www.gencayyildiz.com\/blog\/c-image-nesnesinin-boyutunu-ayarlama\/\" target=\"_blank\">C# Image Nesnesinin Boyutunu Ayarlama<\/a> ve <a href=\"http:\/\/www.gencayyildiz.com\/blog\/asp-net-fileupload-ile-secilen-resmin-boyutunu-kucultme\/\" target=\"_blank\">Asp.NET FileUpload \u0130le Se\u00e7ilen Resmin Boyutunu K\u00fc\u00e7\u00fcltme<\/a> ba\u015fl\u0131kl\u0131 yaz\u0131lar\u0131mda C# ile bir resim boyutlar\u0131n\u0131n nas\u0131l ayarland\u0131\u011f\u0131na farkl\u0131 y\u00f6ntem ve a\u00e7\u0131lardan de\u011finmi\u015ftik.Biliyoruz ki, bir resmin boyutlar\u0131 ne kadar k\u00fc\u00e7\u00fcl\u00fcrse, kapasiteside orant\u0131l\u0131 olarak k\u00fc\u00e7\u00fclecek aksi halde ayn\u0131 mant\u0131kla b\u00fcy\u00fcyecektir.Bu yaz\u0131m\u0131zda bir resmin boyutlar\u0131n\u0131 hi\u00e7 de\u011fi\u015ftirmeden kapasitesini ayarlamay\u0131 inceleyece\u011fiz.<br \/>\n<!--more--><br \/>\nElimde a\u015fa\u011f\u0131daki gibi bir kapasite \u00f6zelliklerine sahip resim bulunmaktad\u0131r.<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2013\/12\/ResimKapasitesiD\u00fc\u015f\u00fcrme.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2013\/12\/ResimKapasitesiD\u00fc\u015f\u00fcrme.png\" alt=\"ResimKapasitesiD\u00fc\u015f\u00fcrme\" width=\"242\" height=\"58\" class=\"aligncenter size-full wp-image-2384\" \/><\/a><br \/>\nBu resmin boyutlar\u0131yla oynayarak kapasitesini orant\u0131l\u0131 ayarlayabiliriz ancak bizim amac\u0131m\u0131z boyut ayarlar\u0131na dokunmadan kapasite ayar\u0131 \u00e7ekmek.<br \/>\nO halde a\u015fa\u011f\u0131daki gibi bir s\u0131n\u0131f yazmam\u0131z gerekmektedir.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    class KapasiteAyarlayici\r\n    {\r\n        private static ImageCodecInfo TipBilgisi(String mimeType)\r\n        {\r\n            int j;\r\n            ImageCodecInfo&#x5B;] encoders;\r\n            encoders = ImageCodecInfo.GetImageEncoders();\r\n            for (j = 0; j &lt; encoders.Length; ++j)\r\n            {\r\n                if (encoders&#x5B;j].MimeType == mimeType)\r\n                    return encoders&#x5B;j];\r\n            }\r\n            return null;\r\n        }\r\n\r\n        public static void KapasiteDusur(Image Resim)\r\n        {\r\n            Bitmap myBitmap;\r\n            ImageCodecInfo myImageCodecInfo;\r\n            System.Drawing.Imaging.Encoder myEncoder;\r\n            EncoderParameter myEncoderParameter;\r\n            EncoderParameters myEncoderParameters;\r\n\r\n            myBitmap = new Bitmap(Resim);\r\n\r\n            myImageCodecInfo = TipBilgisi(&quot;image\/jpeg&quot;);\r\n\r\n            myEncoder = System.Drawing.Imaging.Encoder.Quality;\r\n\r\n            myEncoderParameters = new EncoderParameters(1);\r\n\r\n            \/\/ 1L - 100L aras\u0131nda bir de\u011fer ile kapasite ayar\u0131n\u0131 ger\u00e7ekle\u015ftiriyoruz.\r\n            myEncoderParameter = new EncoderParameter(myEncoder, 1L);\r\n\r\n            myEncoderParameters.Param&#x5B;0] = myEncoderParameter;\r\n            myBitmap.Save(&quot;Kay\u0131t Edilecek Dizin&quot;, myImageCodecInfo, myEncoderParameters);\r\n        }\r\n    }\r\n<\/pre>\n<p>Yukar\u0131daki kod blo\u011funu incelerseniz e\u011fer, hangi formattaki resimle \u00e7al\u0131\u015facaksak &#8220;TipBilgisi&#8221; isimli metodumuz o format\u0131n Enum kar\u015f\u0131l\u0131\u011f\u0131n\u0131 getirmektedir.Daha sonra 1L &#8211; 100L aras\u0131nda verilen bir de\u011fere g\u00f6re resmin kapasitesi ayarlanmakta ve istenilen dizine kay\u0131t i\u015flemi ger\u00e7ekle\u015fmektedir.<\/p>\n<p>Bu i\u015fleme tabi tutulan resmin kapasite boyutundaki de\u011fi\u015fikli\u011fi g\u00f6rmek i\u00e7in a\u015fa\u011f\u0131daki resmi inceleyiniz.<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2013\/12\/ResimKapasitesiD\u00fc\u015f\u00fcrme2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2013\/12\/ResimKapasitesiD\u00fc\u015f\u00fcrme2.png\" alt=\"ResimKapasitesiD\u00fc\u015f\u00fcrme2\" width=\"202\" height=\"50\" class=\"aligncenter size-full wp-image-2387\" \/><\/a><\/p>\n<p>Resmin ilk boyutuyla son boyutunu kar\u015f\u0131la\u015ft\u0131r\u0131rsan\u0131z e\u011fer bu algoritma sonucu ne kadar kapasite fark\u0131 oldu\u011funu g\u00f6rebileceksiniz.Lakin bir ka\u00e7 husustan bahsetmeninde faydas\u0131 var.<br \/>\nBu algoritma en performansl\u0131 olarak &#8220;.jpg&#8221;, &#8220;.jpeg&#8221; format\u0131ndaki resim dosyalar\u0131nda \u00e7al\u0131\u015fmaktad\u0131r.<br \/>\nResim dosyas\u0131n\u0131n kapasitesi de\u011fi\u015ftik\u00e7e boyut sabit kalacakt\u0131r lakin kapasiteye do\u011fru orant\u0131l\u0131 olarak \u00e7\u00f6z\u00fcn\u00fcrl\u00fckte art\u0131p azalacakt\u0131r.<\/p>\n<p>Bu durumlar\u0131 g\u00f6z \u00f6n\u00fcne al\u0131p bu algoritmay\u0131 kullanman\u0131z\u0131 tavsiye ederim.<br \/>\n\u0130yi \u00e7al\u0131\u015fmalar dilerim..<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>C# Image Nesnesinin Boyutunu Ayarlama ve Asp.NET FileUpload \u0130le Se\u00e7ilen Resmin Boyutunu K\u00fc\u00e7\u00fcltme ba\u015fl\u0131kl\u0131 yaz\u0131lar\u0131mda C# ile bir resim boyutlar\u0131n\u0131n nas\u0131l ayarland\u0131\u011f\u0131na farkl\u0131 y\u00f6ntem ve a\u00e7\u0131lardan de\u011finmi\u015ftik.Biliyoruz ki, bir resmin boyutlar\u0131 ne kadar k\u00fc\u00e7\u00fcl\u00fcrse,&#46;&#46;&#46;<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,338],"tags":[27,329],"class_list":["post-2380","post","type-post","status-publish","format-standard","hentry","category-c-sharp-c","category-c-5-0","tag-c","tag-image"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/2380","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/comments?post=2380"}],"version-history":[{"count":0,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/2380\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=2380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=2380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=2380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}