本文整理汇总了Golang中golang.org/x/mobile/exp/f32.Affine.Identity方法的典型用法代码示例。如果您正苦于以下问题:Golang Affine.Identity方法的具体用法?Golang Affine.Identity怎么用?Golang Affine.Identity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/mobile/exp/f32.Affine
的用法示例。
在下文中一共展示了Affine.Identity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestAffineMask
func TestAffineMask(t *testing.T) {
f, err := os.Open("../../../testdata/testpattern.png")
if err != nil {
t.Fatal(err)
}
defer f.Close()
srcOrig, _, err := image.Decode(f)
if err != nil {
t.Fatal(err)
}
b := srcOrig.Bounds()
src := image.NewRGBA(b)
draw.Draw(src, src.Rect, srcOrig, b.Min, draw.Src)
mask := image.NewAlpha(b)
for y := b.Min.Y; y < b.Max.Y; y++ {
for x := b.Min.X; x < b.Max.X; x++ {
mask.Set(x, y, color.Alpha{A: uint8(x - b.Min.X)})
}
}
want := image.NewRGBA(b)
draw.DrawMask(want, want.Rect, src, b.Min, mask, b.Min, draw.Src)
a := new(f32.Affine)
a.Identity()
got := image.NewRGBA(b)
affine(got, src, b, mask, a, draw.Src)
if !imageEq(got, want) {
gotPath, err := writeTempPNG("testpattern-mask-got", got)
if err != nil {
t.Fatal(err)
}
wantPath, err := writeTempPNG("testpattern-mask-want", want)
if err != nil {
t.Fatal(err)
}
t.Errorf("got\n%s\nwant\n%s", gotPath, wantPath)
}
}
示例2: TestAffine
func TestAffine(t *testing.T) {
f, err := os.Open("../../../testdata/testpattern.png")
if err != nil {
t.Fatal(err)
}
defer f.Close()
srcOrig, _, err := image.Decode(f)
if err != nil {
t.Fatal(err)
}
src := image.NewRGBA(srcOrig.Bounds())
draw.Draw(src, src.Rect, srcOrig, srcOrig.Bounds().Min, draw.Src)
const (
pixW = 100
pixH = 100
ptW = geom.Pt(50)
ptH = geom.Pt(50)
)
cfg := event.Config{
Width: ptW,
Height: ptH,
PixelsPerPt: float32(pixW) / float32(ptW),
}
got := image.NewRGBA(image.Rect(0, 0, pixW, pixH))
blue := image.NewUniform(color.RGBA{B: 0xff, A: 0xff})
draw.Draw(got, got.Bounds(), blue, image.Point{}, draw.Src)
b := src.Bounds()
b.Min.X += 10
b.Max.Y /= 2
var a f32.Affine
a.Identity()
a.Scale(&a, cfg.PixelsPerPt, cfg.PixelsPerPt)
a.Translate(&a, 0, 24)
a.Rotate(&a, float32(math.Asin(12./20)))
// See commentary in the render method defined in portable.go.
a.Scale(&a, 40/float32(b.Dx()), 20/float32(b.Dy()))
a.Inverse(&a)
affine(got, src, b, nil, &a, draw.Over)
ptTopLeft := geom.Point{0, 24}
ptBottomRight := geom.Point{12 + 32, 16}
drawCross(got, 0, 0)
drawCross(got, int(ptTopLeft.X.Px(cfg.PixelsPerPt)), int(ptTopLeft.Y.Px(cfg.PixelsPerPt)))
drawCross(got, int(ptBottomRight.X.Px(cfg.PixelsPerPt)), int(ptBottomRight.Y.Px(cfg.PixelsPerPt)))
drawCross(got, pixW-1, pixH-1)
const wantPath = "../../../testdata/testpattern-window.png"
f, err = os.Open(wantPath)
if err != nil {
t.Fatal(err)
}
defer f.Close()
wantSrc, _, err := image.Decode(f)
if err != nil {
t.Fatal(err)
}
want, ok := wantSrc.(*image.RGBA)
if !ok {
b := wantSrc.Bounds()
want = image.NewRGBA(b)
draw.Draw(want, b, wantSrc, b.Min, draw.Src)
}
if !imageEq(got, want) {
gotPath, err := writeTempPNG("testpattern-window-got", got)
if err != nil {
t.Fatal(err)
}
t.Errorf("got\n%s\nwant\n%s", gotPath, wantPath)
}
}