Exemple #1
0
    radius = width // 2
#set up the effect color to white(255,255,255)
newRed = 255
newBlue = 255
newGreen = 255
# newRow is row number of new image
newRow = 0
for row in range(height):  #go through every row
    # outer loop is top-down
    for col in range(width):  #go through column
        #inner loop is left-to-right
        newCol = col
        if sqrt((width / 2 - col)**2 + (height / 2 - row)**2) <= radius:
            green = int(0.7152 * origImage.getGreen(row, col))
            red = int(0.2126 * origImage.getRed(row, col))
            blue = int(0.0722 * origImage.getBlue(row, col))
            gray = green + red + blue
            newImage.setPixel(newRow, newCol, gray, gray,
                              gray)  #paste to new image
        else:
            newImage.setPixel(newRow, newCol, newRed, newGreen,
                              newBlue)  # paste to new image
    newRow = newRow + 1
# Save the new image with "Black".
newImage.save("black-" + filename)

# Draw the telescoped image
win = GraphicsWindow()
canvas = win.canvas()
canvas.drawImage(newImage)
win.wait()
from ezgraphics import GraphicsImage, GraphicsWindow

filename = input("Enter the name of the image file: ")

# Load the image from the file.
image = GraphicsImage(filename)

# Process the image.
width = image.width()
height = image.height()
for row in range(height):
    for col in range(width):
        # Get the current pixel color.
        red = image.getRed(row, col)
        green = image.getGreen(row, col)
        blue = image.getBlue(row, col)

        # Filter the pixel.
        newRed = 255 - red
        newGreen = 255 - green
        newBlue = 255 - blue

        # Set the pixel to the new color.
        image.setPixel(row, col, newRed, newGreen, newBlue)

# Display the image on screen.
win = GraphicsWindow()
canvas = win.canvas()
canvas.drawImage(image)
win.wait()
canvas = win.canvas()
imageWidth = origImage.width()
imageHeight = origImage.height()

# define new image dimensions
newImage = GraphicsImage(imageWidth, imageHeight)

# output the size of image
print(imageWidth)
print(imageHeight)

# edit the image
for row in range(imageHeight):
    for col in range(imageWidth):
        red = origImage.getRed(row, col)
        newRed = int(red * 1.3)
        # if the red exceed the RGB range, it will set to the maximum
        if newRed > 255:
            newRed = 255
        green = origImage.getGreen(row, col)
        blue = origImage.getBlue(row, col)
        # set the colors of the image
        newImage.setPixel(row, col, newRed, green, blue)

# display image
canvas.drawImage(origImage)
canvas.drawImage(newImage)
win.wait()

# output image file
newImage.save("Golden Bridge Sunset.gif")