canvas icon indicating copy to clipboard operation
canvas copied to clipboard

How to save canvas as png with transparent background

Open t42ji2ji opened this issue 4 years ago • 1 comments

I want save canvas as png photo. But the background is always black.

                fDst, err := os.Create("out2.png")
		if err != nil {
			log.Fatal(err)
		}
		defer fDst.Close()

		err = png.Encode(fDst, cv.GetImageData(0, 0, cv.Width(), cv.Height()))
		if err != nil {
			log.Fatal(err)
		}
		wnd.Close()

t42ji2ji avatar Jul 14 '21 01:07 t42ji2ji

Sorry for missing this. I'll answer now just for completeness I guess.

GetImageData currently only returns the RGB channels, no alpha. At the moment the only way to get alpha would be to use the software rendering backend, but obviously then the performance will be bad.

tfriedel6 avatar Aug 26 '21 08:08 tfriedel6