Advertisement
Dettefin

Scale an image

May 31st, 2014
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. #scale down a picture by half in each dimension. Error is at bottom of page
  2.  
  3. def scaleDown(src, dest) :
  4.   skipRow = "false"
  5.   skipCol = "false"
  6.   destX = 1
  7.   for srcX in range(1, getWidth(src)) :
  8.     if skipRow == "true" :      
  9.       skipRow = "false"
  10.     else :
  11.       skipRow = "true"
  12.       destY = 1 #checking coordinate (1, 1) at the start, then scanning all y in x, then checking next column
  13.       for srcY in range(1, getHeight(src)) :
  14.         if skipCol == "true" :
  15.           skipCol = "false"
  16.         else :
  17.           skipCol = "true"
  18.           srcPixel = getPixel(src, srcX, srcY)
  19.           destPixel = getPixel(dest, destX, destY)
  20.           setColor(destPixel, getColor(srcPixel))
  21.           destY = destY + 1
  22.       destX = destX + 1
  23.  
  24. def scaleDownExercise() :
  25.   srcPic = makePicture(pickAFile())
  26.   destWidth = getWidth(srcPic)/2
  27.   destHeight = getHeight(srcPic) /2 #this is where the error is
  28.   destPic = makeEmptyPicture(destWidth, destHeight)
  29.  
  30.   show(srcPic)
  31.   show(destPic)
  32.   scaleDown(srcPic, destPic)
  33.   repaint(destPic)
  34.  
  35. #error:
  36. #getPixel(picture,x,y): y (= 450) is less than 0 or bigger than the height (= 449)
  37. #The error was:
  38. #Inappropriate argument value (of correct type).
  39. #An error occurred attempting to pass an argument to a function.
  40. #Please check line 19 of C:\Users\Matt\Desktop\Test Python\test3.py
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement