def setPixel(self, col, row, RGBlist): """Sets this pixel's RGB values, e.g., [255, 0, 0].""" # Obsolete - convert the row so that row zero refers to the bottom row of pixels. #row = self.height - row - 1 color = Color(RGBlist[0], RGBlist[1], RGBlist[2]) # create color from RGB values self.image.setRGB(col, row, color.getRGB())
def setPixels(self, pixels): """Sets image to the provided 2D list of pixels (col, row) - each pixel is a list of RGB values, e.g., [255, 0, 0].""" self.height = len(pixels) # get number of rows self.width = len(pixels[0]) # get number of columns (assume all columns have same length #for row in range(self.height-1, 0, -1): # iterate through all rows for row in range(0, self.height): # iterate through all rows for col in range(self.width): # iterate through every column on this row RGBlist = pixels[row][col] #self.setPixel(col, row, RGBlist) # this works also (but slower) color = Color(RGBlist[0], RGBlist[1], RGBlist[2]) # create color from RGB values self.image.setRGB(col, row, color.getRGB())