Image:
Filter:
Classes | GUI > Views

Image

image component
Location: NOT INSTALLED!

Description

Image enables the drawing of images in the SuperCollider GUI.

Class Methods

.new

Creates a new Image instance. "multiple" here stands for multiple arguments.

Arguments:

multiple

Any of the following:

  • Number to create an empty image of size multiple as width and height

  • Point to create an empty image of size multiple.x as width and multiple.y as height

  • String to create an image from a local file
height

If multiple is a number, then this argument indicates the height of the new image.

.color

Creates a new Image instance filled with the specified color.

Arguments:

... args

Multiple arguments. the last argument should be a valid Color

.open

Creates a new Image instance from the local file at path.

.openSVG

Creates a new Image instance from the local SVG file at path.

Arguments:

path

A String containing the SVG file's path.

size

A Size. SVG contents will be drawn into an image of this size. If not provided, suggested size provided by SVG will be used.

.openURL

NOTE: Not implemented yet.

Creates a new Image instance from a valid image at the specified URL path.

.fromImage

Creates a new Image instance from another Image.

.fromWindow

Creates a new Image from a portion of a Window. this can be used to capture either a window or a specific View.

Arguments:

window

the Window object.

rect

optional. the constrained rect to capture inside the Window. By default, it is the window size.

.closeAllPlotWindows

Close all the Image plot windows currently opened.

.colorToPixel

Convert a Color into a pixel datatype suitable for setting pixel data in the Image class.

Returns:

A 32bit packed Integer in the RGBA format.

.pixelToColor

Convert a 32bit packed Integer in the RGBA format into a Color

Returns:

Class variables and attributes

.formats

returns all the valid image formats as an Array

.compositingOperations

returns all the valid compositing operations you can use when drawing an Image as an Array

.interpolations

returns an Array of the different levels of interpolation you can specify when drawing an Image.

.resizeModes

returns an Array of the different resize modes you can specify when changing the size of an Image.

.allPlotWindows

Returns an array of all the Image plot windows currently opened.

Inherited class methods

Instance Methods

commons / general attributes

.width

returns or set the width of the receiver

.height

returns or set the height of the receiver

.setSize

set the size of the receiver

.bounds

returns the bounds of the receiver.

.free

deallocate the receiver. this method is useful if you want to manage and reclaim yourself resources. otherwise you do not need to call this method since each object is automatically garbage collected.

.scalesWhenResized

flag to tell or set if the receiver should update its bitmap representation to scale when a resize operation is performed

.url

returns or set the url of the receiver. Returning only if any where supplied at creation, otherwise returns nil. Setting may be used for different purpose but try to supply a valid one since it is used for archiving the image as an object.

.interpolation

get or set the level of interpolation used when rendering the image - it has not effect when the Image is accelerated. see *interpolations for a valid range of values.

saving and archiving

.write

write the Image to a file.

Arguments:

path

the location where to save it

format

(optional) format to use. see Image.formats for supported formats. If nil, it will get the format depending on the path extension.

quality

The quality factor must be in the range 0 to 100 or -1. Specify 0 to obtain small compressed files, 100 for large uncompressed files, and -1 (the default) to use the default settings.

rendering

.plot

plots the image in a Window.

Arguments:

name

the title of the Window. may be nil.

bounds

the bounds of the Window. may be nil.

freeOnClose

flag to tell if the Window should free the Image when closed.

background

additional background to apply to the Window. may be useful for artifacts due to alpha / compositing...

showInfo

shows pixel coordinates while the mouse is over the image's plot window.

.draw

shortcut for drawing inside an image. equivalent to :

.drawStringAtPoint

renders *correctly* a String inside an Image :) // to fix to have a compliant interface

.drawAtPoint

render the image or a portion of it in the current graphic context.

Arguments:

point

the Point where to draw it

fromRect

the portion of the Image to use

operation

the compositing operation to use. 'sourceOver' is the default.

fraction

the opacity to use, ranging from 0.0 (fully transparent) to 1.0 (fully opaque)

.drawInRect

render the image or a portion of it in a specified rectangle of the current graphic context. This may stretch the image depending on the destination rect.

Arguments:

rect

the Rect where to draw it

fromRect

the portion of the Image to use

operation

the compositing operation to use. 'sourceOver' is the default.

fraction

the opacity to use, ranging from 0.0 (fully transparent) to 1.0 (fully opaque)

.tileInRect

tile the image or a portion of it in a specified rectangle of the current graphic context. This may stretch the image depending on the destination rect.

Arguments:

rect

the Rect where to draw it

fromRect

the portion of the Image to use

operation

the compositing operation to use. 'sourceOver' is the default.

NOTE: Compositing operations are currently disabled for tileInRect
opacity

the opacity to use, ranging from 0.0 (fully transparent) to 1.0 (fully opaque)

Instance Methods / accessing and setting pixels

.setPixel

fill a pixel located at x @ y.

Arguments:

rgbaInteger

an 32 bit Integer containing color information packed as 8bit RGBA

x

the x position of the pixel in the image

y

the y position of the pixel in the image

.getPixel

retrieve the pixel value at x @ y as a RGBA integer

.setColor

fill the pixel located at x @ y with the specified color.

.getColor

retrieve the pixel value at x @ y as a Color.

.pixels

retrieve or set all the pixels of the receiver.

NOTE: Careful: the returned Array is a Int32Array of size receiver.width * receiver.height containing all pixel values as 32bit Integer. See *colorToPixel and *pixelToColor.

Arguments:

array

an Int32Array of size receiver.width * receiver.height containing all pixel values as 32bit Integer

.loadPixels

load all the pixels of the receiver in an array. it is better and faster to call this function instead of -pixels if you plan to retrieve frequently the pixel data (since it won't allocate a new array everytime !)

Arguments:

array

the array that will be filled. Should be an Int32Array of size receiver.width * receiver.height.

region

the targeted rectangular region. (nil by default, meaning full size)

start

the start index of the array.

.setPixels

set the pixels in a specific portion of the receiver.

Arguments:

array

an Int32Array of size rect.width * rect.height containing all pixel values as 32bit Integer

region

a rectangle defining the portion to update in the receiver. By default rect is nil, meaning full image size.

start

the array start index.

.pixelRatio

Get/set pixel ratio of the image.

This does NOT affect the content of the image, only how it is interpreted when it is drawn onto a View or another Image. For example, in a high DPI context, the pixel ratio of a View might be 2. When drawing an image with a pixelRatio of 1, each pixel of the image will fill a 2x2 area of the View. If both the Image and the View had a pixel ratio of 2, each pixel would be 1:1 with pixels in the View.

By default, the pixelRatio of all Images is 1 - this ensures that an image will look the same when drawn on a normal or a high DPI view. Setting a custom (!= 1) pixelRatio should generally only be done to draw specially rendered high DPI images to a View that is known to be high DPI.

Note that when drawing to an Image using Pen, pixelRatio is accounted for - so, a line of width 1 will have a true width of 1px for an image where image.pixelRatio==1, and a true width of 2px where image.pixelRatio==2.

Inherited instance methods