Image:
Filter:
Classes | GUI > Views

Image : Object

image component
Source: QImage.sc
Subclasses: QImage

Description

Image enables the drawing of images in the SuperCollider GUI.

Class Methods

Image.new(multiple, height)

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.

Image.color( ... args)

Creates a new Image instance filled with the specified color.

Arguments:

... args

Multiple arguments. the last argument should be a valid Color

Image.open(path)

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

Image.openSVG(path, size)

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.

Image.openURL(url, timeout: 60)

NOTE: Not implemented yet.

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

Image.fromImage(image)

Creates a new Image instance from another Image.

Image.fromWindow(window, rect)

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.

Image.closeAllPlotWindows

Close all the Image plot windows currently opened.

Image.colorToPixel(color)

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.

Image.pixelToColor(pixel)

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

Returns:

Class variables and attributes

Image.formats(rw: "r")

returns all the valid image formats as an Array

Image.compositingOperations

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

Image.interpolations

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

Image.resizeModes

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

Image.allPlotWindows

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

Inherited class methods

Instance Methods

commons / general attributes

.width

.width = w

returns or set the width of the receiver

.height

.height = h

returns or set the height of the receiver

.setSize(width, height, resizeMode)

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

.scalesWhenResized = value

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

.url

.url = newURL

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

.interpolation = mode

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(path, format, quality: -1)

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(name, bounds, freeOnClose: false, background, showInfo: true)

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(aFunction)

shortcut for drawing inside an image. equivalent to :

.drawStringAtPoint(string, point, font, color)

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

.drawAtPoint(point, fromRect, operation: 'sourceOver', fraction: 1.0)

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(rect, fromRect, operation: 'sourceOver', fraction: 1.0)

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(rect, fromRect, operation: 'sourceOver', opacity: 1.0)

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(rgbaInteger, x, y)

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(x, y)

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

.setColor(color, x, y)

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

.getColor(x, y)

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

.pixels

.pixels = array

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(array, region, start: 0)

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(array, region, start: 0)

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

.pixelRatio = ratio

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

Undocumented instance methods

.archiveAsCompileString

.copy

.fill(color)

.isValid

.name

.name = value

.smooth

.smooth = smooth