python 生成png

举报
风吹稻花香 发表于 2022/04/30 00:31:46 2022/04/30
【摘要】 python opencv生成背景透明图标_Tqdada的博客-CSDN博客 import numpy as npimport cv2import math img = np.zeros((230,230), dtype=np.uint8)img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)img[:...

python opencv生成背景透明图标_Tqdada的博客-CSDN博客


      import numpy as np
      import cv2
      import math
      img = np.zeros((230,230), dtype=np.uint8)
      img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
      img[:,:,:] = 255
      #画星号,可以根据需要绘制其他形状
      #line1 0°
      color = (0,0,0)
      width = 55
      cv2.line(img, (115, 30), (115, 115), color, width)
      #line2 72°
      x2 = 115+85*math.sin(0.4*math.pi)
      y2 = 115-85*math.cos(0.4*math.pi)
      cv2.line(img, (115,115),(int(x2),int(y2)),color,width)
      #line3 -72°
      x3 = 230-int(x2)
      y3 = int(y2)
      cv2.line(img, (115,115), (x3,y3), color, width)
      #line4 144°
      x4 = 115+100*math.sin(0.2*math.pi)
      y4 = 115+100*math.cos(0.2*math.pi)
      cv2.line(img, (115,115), (int(x4),int(y4)), color, width)
      #line5 216°
      x5 = 230-int(x4)
      y5 = int(y4)
      cv2.line(img, (115,115), (x5,y5), color, width)
      #创建四通道图片
      b,g,r = cv2.split(img)
      a = np.ones(b.shape,dtype=b.dtype)*255
      for i in range(230):
         for j in range(230):
             if(b[i][j] == 255 and g[i][j] == 255 and r[i][j] == 255):
                  a[i][j] = 0
      img_al = cv2.merge((b,g,r,a))
      #查看保存图片
      cv2.imshow("img", img_al)
      cv2.imwrite("img.png", img_al)
      cv2.waitKey(0)
  
 

————————————————
版权声明:本文为CSDN博主「Tqdada」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Tqdada/article/details/105725007

文章来源: blog.csdn.net,作者:AI视觉网奇,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/jacke121/article/details/124464529

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。