<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] ## image - image實現了基本的2D圖片庫 - Image接口可以通過調用如NewRGBA和NewPaletted函數等獲得 - Decode函數解碼包含GIF、JPEG或PNG格式圖像數據的輸入流獲得 - 解碼任何具體圖像類型之前都必須注冊對應類型的解碼函數。注冊過程一般是作為包初始化的副作用(類似mysql) ``` import _ "image/png" ``` 語法 ``` type Point func Pt(X, Y int) Point func (p Point) Eq(q Point) bool func (p Point) Add(q Point) Point func (p Point) Sub(q Point) Point func (p Point) Mul(k int) Point func (p Point) Div(k int) Point func (p Point) In(r Rectangle) bool func (p Point) Mod(r Rectangle) Point func (p Point) String() string // 矩形 type Rectangle func Rect(x0, y0, x1, y1 int) Rectangle func (r Rectangle) Canon() Rectangle func (r Rectangle) Dx() int func (r Rectangle) Dy() int func (r Rectangle) Size() Point func (r Rectangle) Empty() bool func (r Rectangle) Eq(s Rectangle) bool func (r Rectangle) In(s Rectangle) bool func (r Rectangle) Overlaps(s Rectangle) bool func (r Rectangle) Add(p Point) Rectangle func (r Rectangle) Sub(p Point) Rectangle func (r Rectangle) Intersect(s Rectangle) Rectangle func (r Rectangle) Union(s Rectangle) Rectangle func (r Rectangle) Inset(n int) Rectangle func (r Rectangle) String() string type Uniform func NewUniform(c color.Color) *Uniform func (c *Uniform) At(x, y int) color.Color func (c *Uniform) Bounds() Rectangle func (c *Uniform) ColorModel() color.Model func (c *Uniform) Convert(color.Color) color.Color func (c *Uniform) Opaque() bool func (c *Uniform) RGBA() (r, g, b, a uint32) type Alpha func (p *Alpha) AlphaAt(x, y int) color.Alpha //獲取指定點的透明度 func (p *Alpha) At(x, y int) color.Color   //獲取指定點的color(指定點的紅綠藍的透明度) func (p *Alpha) Bounds() Rectangle   //獲取alpha的邊界 func (p *Alpha) ColorModel() color.Model //獲取alpha的顏色模型 func (p *Alpha) Opaque() bool      //檢查alpha是否完全不透明 func (p *Alpha) PixOffset(x, y int) int   //獲取指定像素相對于第一個像素的相對偏移量 func (p *Alpha) Set(x, y int, c color.Color) //設定指定位置的color func (p *Alpha) SetAlpha(x, y int, c color.Alpha) //設定指定位置的alpha func (p *Alpha) SubImage(r Rectangle) Image //獲取p圖像中被r覆蓋的子圖像,父圖像和子圖像公用像素 // 以下類型都還有 type Alpha 的方法 type Gray16 type Gray type RGBA64 type RGBA type Alpha16 type NRGBA type NRGBA64 type Paletted type YCbCr ``` ### image.Rect 生成矩形 ``` image.Rect(0, 0, 500, 200) ``` ### image.Point ``` func main() { pt := image.Point{X: 5, Y: 5} fmt.Println(pt) //(5,5) ,輸出一個點位置(X,Y) fmt.Println(image.Pt(1, 2)) //(1,2) ,Pt輸出一個點位置的簡寫形式 fmt.Println(pt.Add(image.Pt(1, 1))) //(6,6),兩個點求和 fmt.Println(pt.String()) //(5,5) ,以字符串形式輸出點 fmt.Println(pt.Eq(image.Pt(5, 5))) //true,判斷兩個點是否完全相等 fmt.Println(pt.In(image.Rect(0, 0, 10, 10))) //true,判斷一個點是否在矩陣中 fmt.Println(pt.Div(2)) //(2,2),求點的商 ? fmt.Println(pt.Mul(2)) // (10,10),求點的乘積 fmt.Println(pt.Sub(image.Pt(1, 1))) // (4,4),求兩個點的差fmt.Println(pt.Mod(image.Rect(9, 8, 10, 10))) // (9,9),dx=10-9=1,dy=10-8=2,9-5=4,4是1和2的倍數并且(9,9)在矩陣中 } ``` ### image.NewAlpha / Alpha16 利用給定矩形邊界產生一個alpha ``` file, err := os.Create("test.jpeg") if err != nil { log.Fatal(err) } defer file.Close() alpha := image.NewAlpha(image.Rect(0, 0, dx, dy)) for x := 0; x < dx; x++ { for y := 0; y < dy; y++ { alpha.Set(x, y, color.Alpha{uint8(x % 256)}) //設定alpha圖片的透明度 } } fmt.Println(alpha.At(400, 100)) //144 在指定位置的像素 fmt.Println(alpha.Bounds()) //(0,0)-(500,200) 圖片邊界 fmt.Println(alpha.Opaque()) //false,是否圖片完全透明 fmt.Println(alpha.PixOffset(1, 1)) //501,指定點相對于第一個點的距離 fmt.Println(alpha.Stride) //500,兩個垂直像素之間的距離 jpeg.Encode(file, alpha, nil) //將image信息寫入文件中 ``` ## 示例 ### ``` func main() { file, err := os.Create("test.jpg") if err != nil { log.Fatal(err) } defer file.Close() rgba := image.NewRGBA(image.Rect(0, 0, dx, dy)) for x := 0; x < dx; x++ { for y := 0; y < dy; y++ { rgba.Set(x, y, color.NRGBA{uint8(x % 256), uint8(y % 256), 0, 255}) } } fmt.Println(rgba.At(400, 100)) //{144 100 0 255} fmt.Println(rgba.Bounds()) //(0,0)-(500,200) fmt.Println(rgba.Opaque()) //true,其完全透明 fmt.Println(rgba.PixOffset(1, 1)) //2004 fmt.Println(rgba.Stride) //2000 jpeg.Encode(file, rgba, nil) //將image信息存入文件中 } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看