imagemagick add background to transparent png

C++
convert -flatten img1.png img1-white.png

Source

Also in C++: