I'm making a drawing program where you can later save and export your changes as an image. The non-transparent image option works perfectly, but the transparent option does not. The code I have right now is based on this post.
Whenever I draw a line in the transparent option, nothing on the image shows up. It's completely transparent.
print("Transparent:", str(transparent))
if not transparent:
image = np.zeros((height, width, 3), np.uint8) # initialize image for saving preferences
image[:] = backgroundColorBGR # change background color
for drawing in drawings: # loop through each drawing
cv2.line(image, drawing[0], drawing[1], drawing[2], thickness = drawing[3]) # create line that user drew
cv2.imwrite("yourimage.png", image)
else:
image = np.zeros((height, width, 4), dtype = np.uint8) # 4 channels instead of 3, for transparent images
for drawing in drawings: # loop through each drawing
cv2.line(image, drawing[0], drawing[1], drawing[2], thickness = drawing[3])
cv2.imwrite("yourimage.png", image)
color=(b,g,r,a)to your parameters forcv2.line(). I mean specifically 4 values so you include transparency/alpha. Makeaequal to 255. Or try splitting the channels and drawing on the first 3 as BGR and the last one as greyscale then recombining withnp.dstack().