Image Functions Reference

< CS101

For reference, here are all the functions, such as pixel.setRed(number); to load and manipulate images.
image = new SimpleImage("flowers.jpg"); Set the variable image to hold the "flowers.jpg" image
image.setZoom(5); Set the image to print at 5x size on screen. Useful to make changes on very small images such as "x.png" visible.
print(image); Print the image to the screen.
pixel = image.getPixel(0, 0); Retrieve the pixel at x,y (0, 0) and store it in a variable named pixel (i.e. the upper left pixel). Changes on that pixel, e.g. pixel.setRed(255);, change the pixel in the original image.
print(pixel); Print the values for one pixel, in the format "r:200 g:12 b:166"
pixel.setRed(number);
pixel.setGreen(number);
pixel.setBlue(number);
Change the pixel's red value to be 255 (we can specify any value 0..255 within the parenthesis). There are analogous functions pixel.setGreen(number); and pixel.setBlue(number);for the other colors. If the number is outside the range 0..255, it is automatically limited to 0 or 255.
r = pixel.getRed();
g = pixel.getGreen();
b = pixel.getBlue();
Retrieve the red value from a pixel (a number in the range 0..255), and store it in a variable named r. There are analogous functions pixel.getGreen() and pixel.getBlue() for the other colors.
image.getWidth(), image.getHeight() Retrieve the width and height of an image.
image.setSize(width, height); Scale an image up or down in size so it has the given width and height.
image.setSameSize(other_image); Scale an image up or down in size, keeping its proportions, so it is at least as big as the other_image specified. Useful for bluescreen code where we want to make the background at least as big as the foreground.

Code Area

Here's a scratch area to try out code.


image-ref-1