{"id":1247,"date":"2022-12-02T11:21:44","date_gmt":"2022-12-02T03:21:44","guid":{"rendered":"https:\/\/fdream.net\/blog\/?p=1247"},"modified":"2022-12-05T11:25:44","modified_gmt":"2022-12-05T03:25:44","slug":"go%e6%8c%87%e5%8d%97%e7%bb%83%e4%b9%a09-%e5%9b%be%e5%83%8f","status":"publish","type":"post","link":"https:\/\/fdream.net\/blog\/article\/1247","title":{"rendered":"Go\u6307\u5357\u7ec3\u4e609-\u56fe\u50cf"},"content":{"rendered":"\n<p>\u8fd9\u4e2a\u662f<a rel=\"noreferrer noopener\" href=\"https:\/\/go.dev\/tour\/list\" target=\"_blank\">A Tour of Go<\/a>\u8fd9\u4e2a\u6559\u7a0b\u91cc\u9762\u7684\u7b2c\u4e5d\u4e2a\u7ec3\u4e60\uff0c<a rel=\"noreferrer noopener\" href=\"https:\/\/tour.go-zh.org\/methods\/25\" target=\"_blank\">\u539f\u9898<\/a>\u5982\u4e0b\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u8fd8\u8bb0\u5f97\u4e4b\u524d\u7f16\u5199\u7684<a href=\"https:\/\/tour.go-zh.org\/moretypes\/18\">\u56fe\u7247\u751f\u6210\u5668<\/a>&nbsp;\u5417\uff1f\u6211\u4eec\u518d\u6765\u7f16\u5199\u53e6\u5916\u4e00\u4e2a\uff0c\u4e0d\u8fc7\u8fd9\u6b21\u5b83\u5c06\u4f1a\u8fd4\u56de\u4e00\u4e2a&nbsp;<code>image.Image<\/code>&nbsp;\u7684\u5b9e\u73b0\u800c\u975e\u4e00\u4e2a\u6570\u636e\u5207\u7247\u3002<\/p>\n\n\n\n<p>\u5b9a\u4e49\u4f60\u81ea\u5df1\u7684&nbsp;<code>Image<\/code>&nbsp;\u7c7b\u578b\uff0c\u5b9e\u73b0<a href=\"https:\/\/go-zh.org\/pkg\/image\/#Image\" target=\"_blank\" rel=\"noreferrer noopener\">\u5fc5\u8981\u7684\u65b9\u6cd5<\/a>\u5e76\u8c03\u7528&nbsp;<code>pic.ShowImage<\/code>\u3002<\/p>\n\n\n\n<p><code>Bounds<\/code>&nbsp;\u5e94\u5f53\u8fd4\u56de\u4e00\u4e2a&nbsp;<code>image.Rectangle<\/code>&nbsp;\uff0c\u4f8b\u5982&nbsp;<code>image.Rect(0, 0, w, h)<\/code>\u3002<\/p>\n\n\n\n<p><code>ColorModel<\/code>&nbsp;\u5e94\u5f53\u8fd4\u56de&nbsp;<code>color.RGBAModel<\/code>\u3002<\/p>\n\n\n\n<p><code>At<\/code>&nbsp;\u5e94\u5f53\u8fd4\u56de\u4e00\u4e2a\u989c\u8272\u3002\u4e0a\u4e00\u4e2a\u56fe\u7247\u751f\u6210\u5668\u7684\u503c&nbsp;<code>v<\/code>&nbsp;\u5bf9\u5e94\u4e8e\u6b64\u6b21\u7684&nbsp;<code>color.RGBA{v, v, 255, 255}<\/code>\u3002<\/p>\n<\/blockquote>\n\n\n\n<p>\u539f\u9898\u6a21\u677f\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"golang.org\/x\/tour\/pic\"\n\ntype Image struct{}\n\nfunc main() {\n\tm := Image{}\n\tpic.ShowImage(m)\n}<\/code><\/pre>\n\n\n\n<p>\u9898\u76ee\u4e2d\u63d0\u5230\u4e86\u4e09\u4e2a\u63a5\u53e3\uff0c\u5206\u522b\u5bf9<code>image<\/code>\u7684\u4e09\u4e2a\u63a5\u53e3\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>type Image interface {\n    \/\/ ColorModel returns the Image's color model.\n    ColorModel() color.Model\n    \/\/ Bounds returns the domain for which At can return non-zero color.\n    \/\/ The bounds do not necessarily contain the point (0, 0).\n    Bounds() Rectangle\n    \/\/ At returns the color of the pixel at (x, y).\n    \/\/ At(Bounds().Min.X, Bounds().Min.Y) returns the upper-left pixel of the grid.\n    \/\/ At(Bounds().Max.X-1, Bounds().Max.Y-1) returns the lower-right one.\n    At(x, y int) color.Color\n}<\/code><\/pre>\n\n\n\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u6839\u636e\u8981\u6c42\u5b9e\u73b0\u8fd9\u4e09\u4e2a\u63a5\u53e3\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n\t\"golang.org\/x\/tour\/pic\"\n\t\"image\/color\"\n\t\"image\"\n)\n\ntype Image struct{}\n\nfunc (i Image) ColorModel() color.Model{\n\treturn color.RGBAModel\n}\n\nfunc (i Image) Bounds() image.Rectangle{\n\treturn image.Rect(0, 0, 256, 256)\n}\n\nfunc (i Image) At(x, y int) color.Color{\n\treturn color.RGBA{uint8(x), uint8(y), uint8(255), uint8(255)}\n}\n\nfunc main() {\n\tm := Image{}\n\tpic.ShowImage(m)\n}<\/code><\/pre>\n\n\n\n<p>\u6267\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/fdream.net\/blog\/wp-content\/uploads\/2022\/12\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"255\" height=\"255\" src=\"https:\/\/fdream.net\/blog\/wp-content\/uploads\/2022\/12\/image-1.png\" alt=\"\" class=\"wp-image-1248\" srcset=\"https:\/\/fdream.net\/blog\/wp-content\/uploads\/2022\/12\/image-1.png 255w, https:\/\/fdream.net\/blog\/wp-content\/uploads\/2022\/12\/image-1-150x150.png 150w\" sizes=\"auto, (max-width: 255px) 100vw, 255px\" \/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u4e2a\u662fA Tour of Go\u8fd9\u4e2a\u6559\u7a0b\u91cc\u9762\u7684\u7b2c\u4e5d\u4e2a\u7ec3\u4e60\uff0c\u539f\u9898\u5982\u4e0b\uff1a \u8fd8\u8bb0\u5f97\u4e4b\u524d\u7f16\u5199\u7684\u56fe\u7247\u751f\u6210\u5668&nbsp;\u5417\uff1f\u6211\u4eec\u518d\u6765\u7f16\u5199\u53e6\u5916\u4e00\u4e2a\uff0c\u4e0d\u8fc7\u8fd9\u6b21\u5b83\u5c06\u4f1a\u8fd4\u56de\u4e00\u4e2a&nbsp;image.Image&nbsp;\u7684\u5b9e\u73b0\u800c\u975e\u4e00\u4e2a\u6570\u636e\u5207\u7247\u3002 \u5b9a\u4e49\u4f60\u81ea\u5df1\u7684&nbsp;Image&nbsp;\u7c7b\u578b\uff0c\u5b9e\u73b0\u5fc5\u8981\u7684\u65b9\u6cd5\u5e76\u8c03\u7528&nbsp;pic.ShowImage\u3002 Bounds&nbsp;\u5e94\u5f53\u8fd4\u56de\u4e00\u4e2a&nbsp;image.Rectangle&nbsp;\uff0c\u4f8b\u5982&nbsp;image.Rect(0, 0, w, h)\u3002 ColorModel&nbsp;\u5e94\u5f53\u8fd4\u56de&nbsp;color.RGBAModel\u3002 At&nbsp;\u5e94\u5f53\u8fd4\u56de\u4e00\u4e2a\u989c\u8272\u3002\u4e0a\u4e00\u4e2a\u56fe\u7247\u751f\u6210\u5668\u7684\u503c&nbsp;v&nbsp;\u5bf9\u5e94\u4e8e\u6b64\u6b21\u7684&nbsp;color.RGBA{v, v, 255, 255}\u3002 \u539f\u9898\u6a21\u677f\u4ee3\u7801\u5982\u4e0b\uff1a \u9898\u76ee\u4e2d\u63d0\u5230\u4e86\u4e09\u4e2a\u63a5\u53e3\uff0c\u5206\u522b\u5bf9image\u7684\u4e09\u4e2a\u63a5\u53e3\uff1a \u63a5\u4e0b\u6765\u6211\u4eec\u6839\u636e\u8981\u6c42\u5b9e\u73b0\u8fd9\u4e09\u4e2a\u63a5\u53e3\uff1a \u6267\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[374],"class_list":["post-1247","post","type-post","status-publish","format-standard","hentry","category-coding","tag-go"],"views":365,"_links":{"self":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/1247","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/comments?post=1247"}],"version-history":[{"count":0,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/1247\/revisions"}],"wp:attachment":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/media?parent=1247"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/categories?post=1247"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/tags?post=1247"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}