{"id":4522,"date":"2022-09-24T18:07:00","date_gmt":"2022-09-24T10:07:00","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=4522"},"modified":"2022-09-24T18:11:46","modified_gmt":"2022-09-24T10:11:46","slug":"c%e4%bd%bf%e7%94%a8freeimage%e5%8c%85%e5%a4%84%e7%90%86%e5%9b%be%e7%89%87","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=4522","title":{"rendered":"C#\u4f7f\u7528FreeImage\u5305\u5904\u7406\u56fe\u7247"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"871\" height=\"71\" src=\"http:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2022\/09\/image-2.png\" alt=\"\" class=\"wp-image-4523\" srcset=\"https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2022\/09\/image-2.png 871w, https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2022\/09\/image-2-300x24.png 300w, https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2022\/09\/image-2-768x63.png 768w, https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2022\/09\/image-2-70x6.png 70w\" sizes=\"(max-width: 871px) 100vw, 871px\" \/><\/figure>\n\n\n\n<p>FreeImage\u8f83\u725bX\u4e4b\u5904\u5728\u4e8e\u652f\u6301\u7684\u56fe\u7247\u683c\u5f0f\u591a<\/p>\n\n\n\n<p><a href=\"http:\/\/freeimage.sourceforge.net\/\">http:\/\/freeimage.sourceforge.net\/<\/a><\/p>\n\n\n\n<p>\u4f7f\u7528NuGet\u6dfb\u52a0FreeImage-dotnet-core<\/p>\n\n\n\n<p>FreeImage \u4f7f\u7528\u53e5\u67c4+API\u7684\u65b9\u5f0f\u5904\u7406<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using FreeImageAPI;\n\nprivate static bool ReduceImage(string filename, int maxSize)\n{\n    try\n    {\n        System.IO.FileInfo fi = new System.IO.FileInfo(filename);\n        if (!fi.Exists)\n        {\n            return false;\n        }\n\n        fi.Attributes = System.IO.FileAttributes.Normal;\n        var fileType = FreeImage.GetFileType(filename, filename.Length);\n        var obj = FreeImage.Load(fileType, filename, FREE_IMAGE_LOAD_FLAGS.DEFAULT);\n        if (obj.IsNull)\n        {\n            return false;\n        }\n\n        var nobj = FreeImage.Rescale(obj, w, h, FREE_IMAGE_FILTER.FILTER_BILINEAR);\n        FreeImage.Save(fileType, nobj, filename, FREE_IMAGE_SAVE_FLAGS.DEFAULT);\n        return true;\n    }\n    catch(Exception e)\n    {\n        Console.WriteLine(e.ToString());\n        return false;\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u989d\u5916\u63a8\u8350\uff1a<\/p>\n\n\n\n<p><a href=\"https:\/\/imagemagick.org\/\">https:\/\/imagemagick.org\/<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.graphicsmagick.org\/\">http:\/\/www.graphicsmagick.org\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>FreeImage\u8f83\u725bX\u4e4b\u5904\u5728\u4e8e\u652f\u6301\u7684\u56fe\u7247\u683c\u5f0f\u591a http:\/\/freeimage.sourceforge.n [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/4522"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4522"}],"version-history":[{"count":5,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/4522\/revisions"}],"predecessor-version":[{"id":4528,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/4522\/revisions\/4528"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}