Classes


Last modified: 2012-12-5

Class Image

The Image object can be used to draw images in an instance of the Sketch. It is possible to load image files from disk, create images from instances of Sketch, or generate them manually. The Image object has several methods to assist in manipulating images once generated. Note that alphablending is on by default in sketch. Certain file formats which contain alpha channels such as PICT or TIFF may have their alpha channel set all off. File formats which do not contain an alpha channel such as JPEG, by default have an alpha channel of all on. If you are having trouble seeing an image when attempting to draw in an instance of Sketch, you may want to either turn off blending with gldisable("blend"), or set the alpha channel to be all on with clearchannel("alpha",1.).

Image in Cycling '74 Reference

Class Summary
Constructor Attributes Constructor Name and Description
 
Image(param1, param2)
The Image object can be used to draw images in an instance of the Sketch.
Field Summary
Field Attributes Field Name and Description
Integer Array[2] get/set 
size[0] is width size[1] is height.
Method Summary
Method Attributes Method Name and Description
void 
adjustchannel(channel, scale, bias)
Adjusts all channel values in the image channel specified by the channel argument, by multiplying the channel value by the value specified by the scale argument and then adding the value specified by the bias argument.
void 
alphachroma(red, green, blue, tolerance, fade, minkey, maxkey)
Generates an alpha channel based on the chromatic distance from the specified RGB target color.
void 
blendchannel(source_object, alpha, source_channel, destination_channel)
Similar to the copychannel method, except supports a blend amount specified by the alpha argument.
void 
blendpixels(source_object, alpha, destination_x, destination_y, source_x, source_y, width, height)
Similar to the copypixels method, except supports alpha blending, including a global alpha value specified by the alpha argument.
void 
clear(red, green, blue, alpha)
Sets all pixels in the image to be the value specified by the red, green, blue, and alpha arguments.
void 
clearchannel(channel, value)
Sets all channel values in the image channel specified by the channel argument to be the value specified by the value argument.
void 
copychannel(source_object, source_channel, destination_channel)
Copies the channel values from the source object's channel specified by the source_channel argument to the destination object's channel specified by the destination_channel argument.
void 
copypixels(source_object, destination_x, destination_y, source_x, source_y, width, height)
Copies pixels from the source object to the location specified by the destination_x and destination_y arguments.
void 
flip(hotizontal_flip, vertical_flip)
Flips the image horizontally and or vertically.
void 
Frees the image data from the native c peer, which is not considered by the JavaScript garbage collector, and may consume lots of memory until the garbage collector decides to run based on JS allocated memory.
void 
fromnamedmatrix(matrixname)
Copies the pixels from the jit.matrix object specified by matrixname to the image.
Float Array 
getpixel(x, y)
Returns an array containing the pixel value at the specified location.
void 
setpixel(x, y, red, green, blue, alpha)
Sets the pixel value at the specified location.
void 
swapxy()
Swaps the axes of the image so that width becomes height and vice versa.
void 
tonamedmatrix(matrixname)
Copy the pixels from the image to the jit.matrix object specified by matrixname.
Class Detail

Image

(param1, param2)
The Image object can be used to draw images in an instance of the Sketch. It is possible to load image files from disk, create images from instances of Sketch, or generate them manually. The Image object has several methods to assist in manipulating images once generated. Note that alphablending is on by default in sketch. Certain file formats which contain alpha channels such as PICT or TIFF may have their alpha channel set all off. File formats which do not contain an alpha channel such as JPEG, by default have an alpha channel of all on. If you are having trouble seeing an image when attempting to draw in an instance of Sketch, you may want to either turn off blending with gldisable("blend"), or set the alpha channel to be all on with clearchannel("alpha",1.).
Example:
// create a new Image instance with default width + height
var myimg = new Image();

// create a new Image instance with the specified witdth + height
var myimg = new Image(width,height);

// create a new Image instance from a file from disk
var myimg = new Image(filename);

// create a new Image instance from another instance of Image
var myimg = new Image(imageobject);

// create a new Image instance from an instance of Sketch
var myimg = new Image(sketchobject);
Parameters:
{mixed optional} param1
can be empty, width, filename, imageobject, sketchobject
{mixed optional} param2
if first parameter is width, this should be height
 
Field Detail
{Integer Array[2] get/set}

size

size[0] is width size[1] is height.
Example:
myimg = new Image("IMG_0032.JPG");

width = myimg.size[0];
height = myimg.size[1];

myimg.size = [400,300];
Method Detail
{void}

adjustchannel

(channel, scale, bias)
Adjusts all channel values in the image channel specified by the channel argument, by multiplying the channel value by the value specified by the scale argument and then adding the value specified by the bias argument. The resulting channel is clipped to the range 0.-1. Acceptable values for the channel argument are the strings: "red", "green", "blue", or "alpha".
Example:
function bang(){
	myimg = new Image("IMG_0032.JPG");
	myimg.adjustchannel("red",0.1,0.5);

	mat = new JitterMatrix();
	myimg.tonamedmatrix(mat.name);
	outlet(0,"jit_matrix",mat.name);
}
Parameters:
{String} channel
"red", "green", "blue", or "alpha"
{Float} scale
{Float} bias
 

{void}

alphachroma

(red, green, blue, tolerance, fade, minkey, maxkey)
Generates an alpha channel based on the chromatic distance from the specified RGB target color. If no tolerance, fade or minkey arguments are specified they are assumed to be 0. If no maxkey argument is specified, it is assumed to be 1.
Example:
function bang(){
	myimg = new Image("IMG_0032.JPG");
	myimg.alphachroma(1.,0.5,0.,0.5,0.9);

	mat = new JitterMatrix();
	myimg.tonamedmatrix(mat.name);
	outlet(0,"jit_matrix",mat.name);
}
Parameters:
{Float} red
{Float} green
{Float} blue
{Float} tolerance
{Float} fade
{Float} minkey
{Float} maxkey
 

{void}

blendchannel

(source_object, alpha, source_channel, destination_channel)
Similar to the copychannel method, except supports a blend amount specified by the alpha argument. The source object can only be an instance of Image (not Sketch). If the source object is not the same size as the destination object, then rectangle composed of the minimum width and height of each, is the rectangle of values which will be blended. Acceptable values for the channel arguments are the strings: "red", "green", "blue", or "alpha".
Example:
function bang(){
	myimg = new Image("IMG_0032.JPG");
	myimg2 = new Image("IMG_0032.JPG");
	myimg.flip(1,0);

	myimg.blendchannel(myimg2, 0.5, "red", "green");

	mat = new JitterMatrix();
	myimg.tonamedmatrix(mat.name);
	outlet(0,"jit_matrix",mat.name);
}
Parameters:
{Maxobj} source_object
{Float} alpha
{String} source_channel
{String} destination_channel
 

{void}

blendpixels

(source_object, alpha, destination_x, destination_y, source_x, source_y, width, height)
Similar to the copypixels method, except supports alpha blending, including a global alpha value specified by the alpha argument. This global alpha value is multiplied by the source object's alpha channel at each pixel. Instances of Sketch do not contain an alpha channel, which is assumed to be all on. The source object can either be an instance of Image, or Sketch.
Example:
function bang(){
	myimg = new Image("IMG_0032.JPG");
	myimg2 = new Image("IMG_0032.JPG");
	myimg.flip(1,0);

	width = myimg.size[0];
	height = myimg.size[1];

	post("width: " + width + "\n");
	post("height: " + height + "\n");

	for(var y=0;y < height;y++){
		for(var x = 0; x < width;x++){
			myimg.blendpixels(myimg2, 0.9, x, y);
		}
	}


	mat = new JitterMatrix();
	myimg.tonamedmatrix(mat.name);
	outlet(0,"jit_matrix",mat.name);
}
Parameters:
{Maxobj} source_object
{Float} alpha
{Integer} destination_x
{Integer} destination_y
{Integer} source_x
{Integer} source_y
{Integer} width
{Integer} height
 

{void}

clear

(red, green, blue, alpha)
Sets all pixels in the image to be the value specified by the red, green, blue, and alpha arguments. If no arguments are specified, these values are assumed to be (0, 0, 0, 1) respectively.
Example:
function bang(){
	myimg = new Image("IMG_0032.JPG");

	myimg.clear(1.,.5,0.,0.5);

	mat = new JitterMatrix();
	myimg.tonamedmatrix(mat.name);
	outlet(0,"jit_matrix",mat.name);
}
Parameters:
{Float} red
{Float} green
{Float} blue
{Float} alpha
 

{void}

clearchannel

(channel, value)
Sets all channel values in the image channel specified by the channel argument to be the value specified by the value argument. If no value argument is specified, it is assumed to be 0. Acceptable values for the channel argument are the strings: "red", "green", "blue", or "alpha".
Example:
function bang(){
	myimg = new Image("IMG_0032.JPG");

	myimg.clearchannel("red",0.5);

	mat = new JitterMatrix();
	myimg.tonamedmatrix(mat.name);
	outlet(0,"jit_matrix",mat.name);
}
Parameters:
{String} channel
{Float} value
 

{void}

copychannel

(source_object, source_channel, destination_channel)
Copies the channel values from the source object's channel specified by the source_channel argument to the destination object's channel specified by the destination_channel argument. The source object can only be an instance of Image (not Sketch). If the source object is not the same size as the destination object, then rectangle composed of the minimum width and height of each, is the rectangle of values which will be copied. Acceptable values for the channel arguments are the strings: "red", "green", "blue", or "alpha".
Example:
function bang(){
	myimg = new Image("IMG_0032.JPG");
	myimg2 = new Image("IMG_0032.JPG");
	myimg.flip(1,0);

	myimg.copychannel(myimg2,"red","green");

	mat = new JitterMatrix();
	myimg.tonamedmatrix(mat.name);
	outlet(0,"jit_matrix",mat.name);
}
Parameters:
{Maxobj} source_object
{String} source_channel
{String} destination_channel
 

{void}

copypixels

(source_object, destination_x, destination_y, source_x, source_y, width, height)
Copies pixels from the source object to the location specified by the destination_x and destination_y arguments. The initial x and y offset into the source and size of the rectangle copied can be speified by the source_x, source_y, width and height arguments. If these are not present an x and y offset of zero and width and height equal to the source image is assumed. No scaling of pixels is supported. The source object can either be an instance of Image, or Sketch.
Example:
function bang(){
	myimg = new Image("IMG_0032.JPG");
	myimg2 = new Image("IMG_0032.JPG");
	myimg.flip(1,0);

	width = myimg.size[0];
	height = myimg.size[1];

	post("width: " + width + "\n");
	post("height: " + height + "\n");

	for(var y=0;y < height;y++){
		for(var x = 0; x < width;x++){
			myimg.copypixels(myimg2, x, y);
		}
	}


	mat = new JitterMatrix();
	myimg.tonamedmatrix(mat.name);
	outlet(0,"jit_matrix",mat.name);
}
Parameters:
{Maxobj} source_object
{Integer} destination_x
{Integer} destination_y
{Integer} source_x
{Integer} source_y
{Integer} width
{Integer} height
 

{void}

flip

(hotizontal_flip, vertical_flip)
Flips the image horizontally and or vertically. Arguments can be 0 or 1, where 0 is no flip, and 1 is flip.
Example:
function bang(){
	myimg = new Image("IMG_0032.JPG");

	myimg.flip(1,0);

	mat = new JitterMatrix();
	myimg.tonamedmatrix(mat.name);
	outlet(0,"jit_matrix",mat.name);
}
Parameters:
{Boolean} hotizontal_flip
{Boolean} vertical_flip
 

{void}

freepeer

()
Frees the image data from the native c peer, which is not considered by the JavaScript garbage collector, and may consume lots of memory until the garbage collector decides to run based on JS allocated memory. Once called, the Image object is not available for any other use.
Example:
function bang(){
	myimg = new Image("IMG_0032.JPG");

	mat = new JitterMatrix();
	myimg.tonamedmatrix(mat.name);
	outlet(0,"jit_matrix",mat.name);

	myimg.freepeer();
}

{void}

fromnamedmatrix

(matrixname)
Copies the pixels from the jit.matrix object specified by matrixname to the image.
Example:
function bang(){
	mat = new JitterMatrix();
	myimg = new Image("IMG_0032.JPG");
	myimg.tonamedmatrix(mat.name);
	myimg2 = new Image();

	myimg2.fromnamedmatrix(mat.name);

	myimg2.flip(0,1);
	myimg2.tonamedmatrix(mat.name);
	outlet(0,"jit_matrix",mat.name);

}
Parameters:
{String} matrixname
 

{Float Array}

getpixel

(x, y)
Returns an array containing the pixel value at the specified location. This array is ordered RGBA, i.e. array element 0 is red, 1, green, 2, blue, 3 alpha. Color values are floating point numbers in the range 0.-1.
Example:
function bang(){
	myimg = new Image("IMG_0032.JPG");

	width = myimg.size[0];
	height = myimg.size[1];

	pixel = myimg.getpixel(width/2,height/2);

	myimg.clear(pixel[0],pixel[1],pixel[2],pixel[3]);
	mat = new JitterMatrix();
	myimg.tonamedmatrix(mat.name);
	outlet(0,"jit_matrix",mat.name);
}
Parameters:
{Integer} x
{Integer} y
 

{void}

setpixel

(x, y, red, green, blue, alpha)
Sets the pixel value at the specified location. Color values are floating point numbers in the range 0.-1.
Example:
function bang(){
	myimg = new Image("IMG_0032.JPG");

	width = myimg.size[0];
	height = myimg.size[1];

	post("width: " + width + "\n");
	post("height: " + height + "\n");

	for(var y=0;y < height;y+=2){
		for(var x = 0; x < width;x+=2){
			pixel = myimg.getpixel(width/2,height/2);
			myimg.setpixel(x,y,pixel[0]/2,pixel[1]/2,pixel[2]/2,.5);
		}
	}


	mat = new JitterMatrix();
	myimg.tonamedmatrix(mat.name);
	outlet(0,"jit_matrix",mat.name);
}
Parameters:
{Integer} x
{Integer} y
{Float} red
{Float} green
{Float} blue
{Float} alpha
 

{void}

swapxy

()
Swaps the axes of the image so that width becomes height and vice versa. The effective result is that the image is rotated 90 degrees counter clockwise, and then flipped vertically.
Example:
function bang(){
	myimg = new Image("IMG_0032.JPG");

	myimg.swapxy();

	mat = new JitterMatrix();
	myimg.tonamedmatrix(mat.name);
	outlet(0,"jit_matrix",mat.name);
}

{void}

tonamedmatrix

(matrixname)
Copy the pixels from the image to the jit.matrix object specified by matrixname.
Example:
function bang(){
	myimg = new Image("IMG_0032.JPG");
	mat = new JitterMatrix();

	myimg.tonamedmatrix(mat.name);

	outlet(0,"jit_matrix",mat.name);
}
Parameters:
{String} matrixname
 

©2012-2013
Max MSP Documentation copied to JsDoc by Tim Schenk SEO Frelancer Berlin. Some examples are by him. Some descriptions of classes, interfaces, properties, methods or events are by him. Until now, most of it is a copy. Published with permission of Cycling '74. This document might be wrong or incomplete. All informations without any warranty. All trademarks are the property of their respective owners. Documentation generated by JsDoc Toolkit on 2012-12-5