Hi everyone
I have made a .png file with paint on windows named source. I want to make a white png file with golang name destination and replace some its pixels with the source. I created the image like below:
destinationImage := image.NewNRGBA(image.Rect(0,0,1920,1080))
for x := 0; x < int(1920); x++ {
for y := 0; y < int(1080); y++ {
destinationImage.Set(x, y, color.White)
}
}
f, _ := os.Create(“Path of my File”)
png.Encode(f, destinationImage)
f.Close()
First of all, is there better method to create a white PNG file? As you see I had to manually set all pixels to white.
Secondly, I use sdl2/img library to manipulate the pixels, like this:
sourceImage,err := img.Load(“Path to source”)
destinationImage,err := img.Load(“Path to destination”)
sourcePixels := sourceImage.Pixels()
destinationPixels := destinationImage.Pixels()
Here I see len(sourcePixels) is 1920x1080x4 and len(destinationPixels) is 1920x1080x3, so when I create the image with paint each pixel has 4 value but when I create the image with Golang each pixel has 3 value, Why is that and how to solve it?