zoukankan      html  css  js  c++  java
  • python basemap画图去除图片的边边,把图片改为透明色

    # 去除图片的边边
    ax = fig.add_axes([0.1, 0.1, 0.7, 0.7]) ax.axis('off') plt.gca().xaxis.set_major_locator(plt.NullLocator()) plt.gca().yaxis.set_major_locator(plt.NullLocator()) plt.subplots_adjust(top=1, bottom=0, left=0, right=1, hspace=0, wspace=0) plt.margins(0, 0) plt.savefig(out_file, transparent=True, bbox_inches='tight', dpi=300, pad_inches=0.0, set_visiable=False)
    from PIL import Image
    
    # 图片改为透明色
    
    img = Image.open(new_file)
    img = img.convert("RGBA")
    datas = img.getdata()
    newData = []
    for item in datas:
        if item != (255, 255, 255, 0):
             pass
        if item[0] == 255 and item[1] == 255 and item[2] == 255:
             newData.append((255, 255, 255, 0))
        else:
             newData.append(item)
    img.putdata(newData)
    img.save('out_file.png', "PNG")
  • 相关阅读:
    c# 中的线程和同步
    Javascript 观察者模式
    连接SQLite 创建ADO.net实体类
    给软件增加注册功能 c#
    log4net 使用步骤
    C# 操作 Excel
    PCL编译历程
    设计模式
    kinect
    eclipse配置servlet错误
  • 原文地址:https://www.cnblogs.com/luochunxi/p/13541160.html
Copyright © 2011-2022 走看看