{"id":206973,"date":"2025-07-08T08:10:43","date_gmt":"2025-07-08T00:10:43","guid":{"rendered":"https:\/\/server.hk\/cnblog\/206973\/"},"modified":"2025-07-08T08:10:43","modified_gmt":"2025-07-08T00:10:43","slug":"%e4%bd%bf%e7%94%a8-fyne-golang-%e8%bf%9b%e8%a1%8c%e9%ab%98%e6%95%88%e7%94%bb%e5%b8%83%e5%88%b7%e6%96%b0","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/206973\/","title":{"rendered":"\u4f7f\u7528 Fyne golang \u8fdb\u884c\u9ad8\u6548\u753b\u5e03\u5237\u65b0"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u4f7f\u7528 Fyne golang \u8fdb\u884c\u9ad8\u6548\u753b\u5e03\u5237\u65b0<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-19 09:51:29<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u4f7f\u7528 Fyne golang \u8fdb\u884c\u9ad8\u6548\u753b\u5e03\u5237\u65b0\u300b<\/span>\u4e3b\u8981\u8bb2\u89e3\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u6709\u4e0b\u9762\u7684\u4ee3\u7801\uff0c\u5b83\u663e\u793a\u4e00\u4e2a\u7a97\u53e3\uff0c\u751f\u6210\u4e00\u4e2a\u5149\u6805\u56fe\u50cf\uff0c\u7136\u540e\u7528\u5b83\u66f4\u65b0\u7a97\u53e3\u5185\u5bb9\u3002 \u7136\u800c\uff0csetcontent \u65b9\u6cd5\u5f88\u6162\uff08\u4f7f\u7528\u5b83\u6211\u6709 100% \u7684 1 \u4e2a cpu \u6838\u5fc3\uff0c\u6ca1\u6709\u5b83\u5219\u51e0\u4e4e\u4e3a 0\uff09\u3002<\/p>\n<p>\u6211\u60f3\u77e5\u9053\u662f\u5426\u6709\u4ec0\u4e48\u529e\u6cd5\u53ef\u4ee5\u6709\u6548\u5730\u5b8c\u6210\u6211\u5728\u8fd9\u91cc\u6240\u505a\u7684\u4e8b\u60c5\uff08\u4fee\u6539\u5e95\u5c42\u6805\u683c\uff0c\u65e0\u8bba\u5982\u4f55\u4f7f\u7528 gpu&#8230;\uff09\u3002\u6211\u5e0c\u671b\u80fd\u591f\u751f\u6210\u5e26\u6709\u5149\u6805\u7684\u56fe\u50cf\uff0c\u7136\u540e\u4ee5\u7ea6 60 fps \u7684\u901f\u5ea6\u6709\u6548\u5730\u663e\u793a\u5b83\u3002<\/p>\n<p>\u4efb\u4f55\u5efa\u8bae\u6216\u5176\u4ed6\u5de5\u5177\u53ef\u4ee5\u505a\u5f97\u66f4\u597d\uff0c\u6211\u4eec\u5c06\u4e0d\u80dc\u611f\u6fc0\u3002<\/p>\n<pre>package main\n\nimport (\n    \"image\/color\"\n    \"math\/rand\"\n    \"time\"\n\n    \"fyne.io\/fyne\/v2\/app\"\n    \"fyne.io\/fyne\/v2\/canvas\"\n)\n\nfunc main() {\n    myApp := app.New()\n    w := myApp.NewWindow(\"Raster\")\n\n    go func() {\n        for {\n            time.Sleep(time.Millisecond * 500)\n            raster := canvas.NewRasterWithPixels(\n                func(_, _, w, h int) color.Color {\n                    return color.RGBA{uint8(rand.Intn(255)),\n                        uint8(rand.Intn(255)),\n                        uint8(rand.Intn(255)), 0xff}\n                })\n            w.SetContent(raster)\n        }\n    }()\n    w.SetFullScreen(true)\n    \/\/ w.Resize(fyne.NewSize(120, 100))\n    w.ShowAndRun()\n}\n<\/pre>\n<p> <\/p>\n<h2>\u6b63\u786e\u7b54\u6848<\/h2>\n<p> <\/p>\n<p>\u8bbe\u7f6e\u7a97\u53e3\u5185\u5bb9\u662f\u4e00\u4e2a\u975e\u5e38\u6602\u8d35\u7684\u8c03\u7528\uff0c\u56e0\u4e3a\u5b83\u5fc5\u987b\u91cd\u65b0\u5e03\u5c40\u6240\u6709\u5185\u5bb9\u5e76\u68c0\u67e5\u5927\u5c0f\u7b49\u3002 \u53ea\u9700\u8c03\u7528 raster.Refresh() \u5373\u53ef\u3002 \u60a8\u8fd8\u53ef\u4ee5\u5728\u5c0f\u90e8\u4ef6\u4e2d\u7f13\u5b58\u5149\u6805\u50cf\u7d20\uff0c\u8fd9\u6837\u60a8\u5c31\u4e0d\u5fc5\u4e3a\u6bcf\u4e2a\u5237\u65b0\u5e27\u521b\u5efa\u65b0\u56fe\u50cf\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\uff01\u66f4\u591a\u5173\u4e8eGolang\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-206973","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206973","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=206973"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206973\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=206973"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=206973"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=206973"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}