{"id":834,"date":"2021-03-14T05:37:16","date_gmt":"2021-03-13T20:37:16","guid":{"rendered":"https:\/\/todosoft.net\/blog\/?p=834"},"modified":"2021-03-14T05:38:09","modified_gmt":"2021-03-13T20:38:09","slug":"post-834","status":"publish","type":"post","link":"https:\/\/todosoft.net\/blog\/?p=834","title":{"rendered":"Bitmap\u3092ImageSource\u306b\u5909\u63db"},"content":{"rendered":"\n<ul class=\"wp-block-list\"><li>Freeze\u3092\u884c\u308f\u306a\u3044\u3068\u3001\u5225\u30b9\u30ec\u30c3\u30c9\u304b\u3089\u89e6\u3063\u305f\u969b\u306b\u30a8\u30e9\u30fc\u3068\u306a\u308b<\/li><li>DeleteObject\u3092\u884c\u308f\u306a\u3044\u3068\u30e1\u30e2\u30ea\u30ea\u30fc\u30af\u304c\u767a\u751f\u3059\u308b<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-luxe-blocks-syntaxhighlighter line-numbers language-csharp\"><code class=\"language-csharp\">public static class BitmapToImageSource\n{\n    [DllImport(\"gdi32.dll\", EntryPoint = \"DeleteObject\")]\n    [return: MarshalAs(UnmanagedType.Bool)]\n    public static extern bool DeleteObject([In] IntPtr hObject);\n\n    \/\/\/ &lt;summary>\n    \/\/\/ Bitmap\u304b\u3089ImageSource\u3078\u30b3\u30f3\u30d0\u30fc\u30c8\n    \/\/\/ &lt;\/summary>\n    \/\/\/ &lt;param name=\"_Bitmap\">&lt;\/param>\n    \/\/\/ &lt;returns>&lt;\/returns>\n    public static ImageSource Convert(Bitmap _Bitmap)\n    {\n        ImageSource objResult = null;\n\n        if (_Bitmap != null)\n        {\n            var objHandle = _Bitmap.GetHbitmap();\n\n            try\n            {\n                objResult = Imaging.CreateBitmapSourceFromHBitmap(objHandle, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());\n                objResult.Freeze();\n            }\n            finally\n            {\n                DeleteObject(objHandle);\n            }\n        }\n\n        return objResult;\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Freeze\u3092\u884c\u308f\u306a\u3044\u3068\u3001\u5225\u30b9\u30ec\u30c3\u30c9\u304b\u3089\u89e6\u3063\u305f\u969b\u306b\u30a8\u30e9\u30fc\u3068\u306a\u308b DeleteObject\u3092\u884c\u308f\u306a\u3044\u3068\u30e1\u30e2\u30ea\u30ea\u30fc\u30af\u304c\u767a\u751f\u3059\u308b<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,15],"tags":[99,100],"class_list":["post-834","post","type-post","status-publish","format-standard","hentry","category-c","category-15","tag-bitmap","tag-imagesource"],"_links":{"self":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/834","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=834"}],"version-history":[{"count":1,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/834\/revisions"}],"predecessor-version":[{"id":835,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/834\/revisions\/835"}],"wp:attachment":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}