Skip to content

Mojo graphics image

mojo:mojo.graphics.Image

Class Image Extends std.resource.Resource#

The Image class.

An image is a rectangular array of pixels that can be drawn to a canvas using one of the Canvas.DrawImage methods.

Images are similar to pixmap's, except that they are optimized for rendering, and typically live in GPU memory.

To load an image from a file, use one of the Load, LoadBump or LoadLight functions.

To create an image from an existing pixmap, use the New( pixmap,... ) constructor.

To create an image that is a 'window' into an existing image, use the New( atlas,rect... ) constructor. This allows you to use images as 'atlases',

To create an 'empty' image, use the New( width,height ) constructor. You can then render to this image by creating a canvas with this image as its render target.

Images also have several properties that affect how they are rendered, including:

  • Handle - the relative position of the image's centre (or 'pivot point') for rendering, where (0.0,0.0) means the top-left of the image while (1.0,1.0) means the bottom-right.
  • Scale - a fixed scale factor for the image.
  • BlendMode - controls how the image is blended with the contents of the canvas. If this is null, this property is ignored and the current canvas blendmode is used to render the image instead.
  • Color - when rendering an image to a canvas, this property is multiplied by the current canvas color and the result is multiplied by actual image pixel colors to achieve the final color to be rendered.
Constructors
New Creates a new Image.
Properties
BlendMode The image blend mode.
Bounds The image bounds. (read only)
Color The image color.
FilePath Image filepath.
Handle The image handle.
Height Image bounds height. (read only)
LightDepth The image light depth.
Material Image material. (read only)
Radius Image bounds radius. (read only)
Rect The image's texture rect. (read only)
Scale The image scale.
Shader Image shader.
ShadowCaster Shadow caster attached to image.
TexCoords Image texture coorinates. (read only)
Texture The image's primary texture.
Vertices Image vertices. (read only)
Width Image bounds width. (read only)
Methods
GetPixel Gets a pixel color.
GetPixelARGB Gets a pixel color.
GetTexture gets an image's texture.
SetTexture Sets an image texture.
Functions
Load Loads an image from file.
LoadBump Loads a bump image from file(s).
LoadLight Loads a light image from file.
Protected methods
OnDiscard