簡體   English   中英

使用JES(python)在圖像上的白色網格線

[英]White gridlines over image using JES (python)

我如何編寫使用JES在圖像上繪制“白色”網格線的程序,該圖像的水平網格線分隔為10個像素,垂直網格線分隔為20個像素?

是的,令人驚訝的是, addLine(picture, startX, startY, endX, endY)只能畫黑線!

因此,讓我們手動進行。 這是一個非常基本的實現:

def drawGrid(picture, color):

  w = getWidth(picture)
  h = getHeight(picture)

  printNow(str(w) + " x " + str(h))

  w_offset = 20  # Vertical lines offset
  h_offset = 10  # Horizontal lines offset

  # Starting at 1 to avoid drawing on the border
  for y in range(1, h):     
    for x in range(1, w):
      # Here is the trick: we draw only 
      # every offset (% = modulus operator)
      if (x % w_offset == 0) or (y % h_offset == 0):
        px = getPixel(picture, x, y)
        setColor(px, color)


file = pickAFile()
picture = makePicture(file) 
# Change the color here
color = makeColor(255, 255, 255) # This is white
drawGrid(picture, color)
show(picture)

注意:使用這里提供的腳本drawLine()函數也可以更有效地實現這一點


輸出:


....... 在此處輸入圖片說明 ...... 在此處輸入圖片說明 .......


暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM