I am using GoMobile to resize and crop images.
I noticed that it runs too slow.
Golang pc: 1.1 s
Gomobile on android: 15.8 s
Android native: 300 ms
Is it because go and gomobile do not use GPU hardware acceleration? and mobile native dose?
my code:
func TestCrop() {
start := time.Now()
str := OnInputImage()
res := base64.NewDecoder(base64.StdEncoding, strings.NewReader(str))
jpgI, _ := jpeg.Decode(res)
dest := image.NewRGBA(image.Rect(0, 0, jpgI.Bounds().Dx(), jpgI.Bounds().Dy()))
gc := draw2dimg.NewGraphicContext(dest)
gc.SetStrokeColor(color.RGBA{0x00, 0x00, 0x00, 0x00})
gc.SetLineWidth(1)
gc.BeginPath()
gc.MoveTo(float64(jpgI.Bounds().Dx())*0.24, float64(jpgI.Bounds().Dy())*0.42)
gc.LineTo(float64(jpgI.Bounds().Dx())*0.71, float64(jpgI.Bounds().Dy())*0.32)
gc.LineTo(float64(jpgI.Bounds().Dx())*0.74, float64(jpgI.Bounds().Dy())*0.58)
gc.LineTo(float64(jpgI.Bounds().Dx())*0.21, float64(jpgI.Bounds().Dy())*0.63)
gc.Close()
gc.FillStroke()
fmt.Println(" crop time 1 :", time.Since(start))
draw.DrawMask(dest, dest.Bounds(), jpgI, image.Point{0, 0}, dest, image.Point{0, 0}, draw.Src)
buf := new(bytes.Buffer)
err := jpeg.Encode(buf, dest, nil)
if err != nil {
fmt.Println(" err=:", err)
}
fmt.Println(" crop time2 :", time.Since(start))
}