线条不会使用ImageDraw在图像上绘制

时间:2019-07-10 17:14:25

标签: python python-3.x image python-imaging-library draw

我正在尝试使用PIL打开图像,然后在其上画一条线,但是它不起作用。我正在尝试显示一个水平,该行是用户水平的水平。

我尝试使用@model Warehouse.Product.ProductTransactionsViewModel @using Warehouse.Helpers; @{ ViewBag.Title = "Product Transactions"; ViewBag.ProgramID = Model.ProgramID; ViewBag.ProductName = Model.ProductName; ViewBag.ProductID = Model.ProductID; Layout = "~/Views/Shared/_PRPopupsLayout.cshtml"; var PRID = (int?)ViewBag.ProductRequestID; } <div class="DisplayMessage"> </div> <div class="popupContentContainer"> @Html.Partial("_ProductTransactions") </div> <div style="text-align:center"> @if(Model.ProductStatus == "Active") { <input type="button" value="Generate Product Document" id="ProductInquiry" name="ProductInquiry" class="grey button" /> } <input type="button" value="Exit" id="exit" name="exit" class="grey button" /> </div> 创建一个新图像,并已经有一个可用的底座,并使用Image.new打开它,并且我还尝试了将坐标直接放入函数中,将两个元组作为变量并将这些变量调用到函数中(如下所示)。基本图像是透明图像。

Image.open

我打开图像,它是 length = 300 # Used as a placeholder integer, as this would change depending on user's level base = Image.open('./level_up/base.png') draw = ImageDraw.Draw(base) pos1 = (280, 324) pos2 = (280, length + 324) draw.line((pos1, pos2), fill=(255, 102, 168), width=20) base.save('./level_up/base2.png') 的空白透明图像,没有任何内容。没有行或其他任何内容。

1 个答案:

答案 0 :(得分:0)

在处理包含透明度的图像(PIL中的模式为“ RGBA”)时,必须显式地将不透明度作为颜色的第4个分量传递。 只需添加“ 255”即可,这意味着在您拨打电话时,填充颜色的透明度为100%,

draw.line((pos1, pos2), fill=(255, 102, 168, 255), width=20)
相关问题