V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
happy61
V2EX  ›  问与答

不太懂 Python ,想实现把图片绘制都一个画布上,不知道应该用哪个库?

  •  
  •   happy61 · Mar 8, 2022 · 1358 views
    This topic created in 1523 days ago, the information mentioned may be changed or developed.

    要把一张 128 图片放到一个 384 的画布上 Js 代码如下:

                    var canvas = document.createElement("canvas");
                    canvas.width = 384;
                    canvas.height = 384;
                    var ctx = canvas.getContext("2d");
                    ctx.drawImage(一张图片,0, 0, 128, 128);
                    
    

    看了好久都在用 Tkinter 库,但是这个好像是 gui 用的。不知道怎样把它转换成 Python 。

    2 replies    2022-03-09 01:16:00 +08:00
    gotounix
        1
    gotounix  
       Mar 8, 2022
    pillow
    happy61
        2
    happy61  
    OP
       Mar 9, 2022
    @gotounix 谢谢

    from PIL import Image
    if __name__ == "__main__":
    images = Image.new("RGB",(300,300),(255,255,255))
    inImg = Image.open('100.jpg')
    images.paste(inImg,(0,0,100,100))
    images.show()
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3141 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 03:17 · PVG 11:17 · LAX 20:17 · JFK 23:17
    ♥ Do have faith in what you're doing.