需要在Jython / Python中指导我的插图代码

时间:2014-09-03 06:37:51

标签: python jes

我无法将我的CGI图片和小插图个人资料图片组合在一起制作小插图图片,图片边缘的图片稍微偏暗,而不会影响其他任何地方的图像,我得到的一切都是如此我认为是正确的,但我的照片在中间显示为暗,而不是显示图像正常,但边缘颜色稍深。

这就是我目前的情况:

def main(): 
inputPic = makePicture(pickAFile()) 
vignette = makePicture(pickAFile())
 addVignette(inputPic, vignette) 
def addVignette(inputPic, vignette): 
if getWidth(inputPic) == getWidth(vignette) and getHeight(inputPic) == getHeight(vignette):
  explore(inputPic)
  explore(vignette)
  px1 = getPixels(inputPic)
  px2 = getPixels(vignette) 
 for px in getPixels(inputPic): 
 x = getX(px)
  y = getY(px)
  px2 = getPixelAt(vignette, x, y)
  x2 = getX(px2)
  y2 = getY(px2)
  r1 = getRed(px)
  r2 = getRed(px2)
  g1 = getGreen(px)
  g2 = getGreen(px2)
  b1 = getBlue(px)
  b2 = getBlue(px2)
  newR = (r1-r2+104)
  newG = (g1-g2+88)
  newB = (b1-b2+48)
  newC = makeColor(newR, newG, newB)
  setColor(px, newC)
 explore(inputPic)
 folder = pickAFolder()
 filename = requestString("enter file name: ")
 path = folder+filename+".jpg" 
 writePictureTo(inputPic, path)

http://i.stack.imgur.com/PqW7K.jpg

图片1是图片需要的内容

http://i.stack.imgur.com/PtS4U.jpg

图片2是我在编码结束时得到的图像

非常感谢能帮助我朝着正确方向前进的任何帮助

1 个答案:

答案 0 :(得分:0)

在我的小朋友模块操作员的帮助下,前3次完全弄错了。

def addVignette(inputPic, vignette):
  # Create empty canvas
  canvas = makeEmptyPicture(getWidth(inputPic), getHeight(inputPic))

  for x in range(0, getWidth(inputPic)):
    for y in range(0, getHeight(inputPic)):
      px = getPixel(canvas, x, y)
      inputPixel = getPixel(inputPic, x, y)
      vignettePixel = getPixel(vignette, x, y)

      # Make a new color from those values
      newColor = getNewColorValues(inputPixel, vignettePixel)

      # Assign this new color to the current pixel of the input image
      setColor(px, newColor)

  explore(canvas)

def getNewColorValues(inputPixel, vignettePixel):

  inputRed = getRed(inputPixel)
  vignetteRed = getRed(vignettePixel)
  inputGreen = getGreen(inputPixel)
  vignetteGreen = getGreen(vignettePixel)
  inputBlue = getBlue(inputPixel)
  vignetteBlue = getBlue(vignettePixel)

  newR = inputRed - (255 % vignetteRed) / 3
  newG = inputGreen - (255 % vignetteGreen) / 3
  newB = inputBlue - (255 % vignetteBlue) / 3

  newC = makeColor(newR, newG, newB)
  return newC