Advertisement
Guest User

getPixel(picture,x,y): y (= 13) is less than 0 or bigger tha

a guest
Jul 9th, 2015
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.01 KB | None | 0 0
  1. import os
  2. def main():
  3.  image = pickAFile() #pick the file
  4.  #imgCheck(image)
  5.  fileSize(image)
  6.  # Pick the file and pass it on to the next part
  7.  
  8. #def imgCheck(image): #check for all image extensions compatible with python
  9.  #here you need to do the checks on whether the file picked is a file compatible with jython
  10. # try:
  11.   #some code here that will throw an exception if an incompatible file is tried, i recommend getHeight(makePicture(image))
  12. # except:
  13.   #show an error message: showInformation("error") etc
  14. # else:
  15.  # fileSize(image)
  16.  
  17. def fileSize(image): # find the size of the file, dale already gave us this code
  18.  fileStats = os.stat(image)
  19.  fsize = fileStats.st_size
  20.  numberSlices(fsize, image)
  21.  
  22. def numberSlices(fsize, image): #find the number of slices needed to keep each slice below 20000bytes
  23.  sliceLimit = 300
  24.  numberSlices = (fsize / sliceLimit) + 1 #add 1 such that uneven divisions will always result in a slice size less than 20000 bytes
  25.  showInformation("Number of Slices:" + str(numberSlices))
  26.  if numberSlices == 1:
  27.   showInformation("This image does not need to be split and can be uploaded")
  28.  else:
  29.   fileExtension(numberSlices, image)
  30.  
  31. def fileExtension(numberSlices, image):
  32.  #find the file extension and the file path minus the extension
  33.  fileExtension = os.path.splitext(image)[1]
  34.  filePath = os.path.splitext(image)[0]
  35.  splitImage(numberSlices, image, fileExtension, filePath)
  36.  
  37. def splitImage(numberSlices, image, fileExtension, filePath): #time to split the image, into noSlices many pieces
  38.  pic = makePicture(image)
  39.  imageOrder = 1 #number each file in the order it is saved
  40.  imageHeight = getHeight(pic)
  41.  imageWidth = getWidth(pic)
  42.  imageX = 0 #x pixel coordinate
  43.  imageY = 0 #y pixel coordinate this has to increment
  44.  splitHeight = imageHeight / (numberSlices-1)
  45.  
  46.  imgHeight = splitHeight
  47.  
  48.  
  49.  
  50.  for imageOrder in range(1, (numberSlices)):
  51.    canvas = makeEmptyPicture(imageWidth,splitHeight)
  52.    fileName = (filePath + "_" + str(imageOrder) + "_" + str(numberSlices) + fileExtension)
  53.    
  54.    sourceX = 0
  55.    for targetX in range(0, imageWidth):
  56.      sourceY = 0  
  57.      for targetY in range(imageY, imgHeight):
  58.        print(str(targetY))
  59.        color = getColor(getPixel(pic, sourceX, sourceY))
  60.        setColor(getPixel(canvas, targetX, targetY), color)
  61.        sourceY = sourceY + 1
  62.      sourceX = sourceX + 1
  63.    writePictureTo(canvas, fileName)
  64.    
  65.    imageY = imageY + splitHeight
  66.    imgHeight = imgHeight + splitHeight
  67.    imageOrder = imageOrder + 1
  68.    showInformation(str(imgHeight))
  69.  
  70.  
  71.  #loop for the last slice starts here this has 2 loops as well.
  72.  #you need to find the height of the last slice in pixels. I used lastHeight = imageHeight - (splitHeight * (numberslices - 1))
  73.  #then specify the fileName again because its a variable
  74.  #canvas = #make the canvas again but this time with the new split height
  75.  #then start the copy function again and make sure you use the right y axis pixels.... think about this.
  76.  
  77.  #writePictureTo(canvas, fileName)
  78.  print "all done!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement