wImage

This class encapsulates a platform-independent image. In wNim, wImage is a wrap of gdiplus image object.

Seealso:wImageList wBitmap wIcon wCursor wIconImage
Consts:The quality used in scale, rescale, transform, and retransform.
ConstsDescription
wImageQualityNearestSpecifies nearest-neighbor interpolation.
wImageQualityBilinearSpecifies high-quality, bilinear interpolation.
wImageQualityBicubicSpecifies high-quality, bicubic interpolation.
wImageQualityNormalSpecifies the default interpolation mode.
wImageQualityHighSpecifies a high-quality mode.
wImageQualityLowSpecifies a low-quality mode.

Used in rotateFlip as flag.

ConstsDescription
wImageRotateNoneFlipNoneSpecifies no rotation and no flipping.
wImageRotateNoneFlipXSpecifies no rotation and a horizontal flip.
wImageRotateNoneFlipYSpecifies no rotation and a vertical flip.
wImageRotateNoneFlipXYSpecifies no rotation, a horizontal flip, and then a vertical flip.
wImageRotate90FlipNoneSpecifies a 90-degree rotation without flipping.
wImageRotate90FlipXSpecifies a 90-degree rotation followed by a horizontal flip.
wImageRotate90FlipYSpecifies a 90-degree rotation followed by a vertical flip.
wImageRotate90FlipXYSpecifies a 90-degree rotation followed by a horizontal flip and then a vertical flip.
wImageRotate180FlipNoneSpecifies a 180-degree rotation without flipping.
wImageRotate180FlipXSpecifies a 180-degree rotation followed by a horizontal flip.
wImageRotate180FlipYSpecifies a 180-degree rotation followed by a vertical flip.
wImageRotate180FlipXYSpecifies a 180-degree rotation followed by a horizontal flip and then a vertical flip.
wImageRotate270FlipNoneSpecifies a 270-degree rotation without flipping.
wImageRotate270FlipXSpecifies a 270-degree rotation followed by a horizontal flip.
wImageRotate270FlipYSpecifies a 270-degree rotation followed by a vertical flip.
wImageRotate270FlipXYSpecifies a 270-degree rotation followed by a horizontal flip and then a vertical flip.

Types

wImageError = object of wError
  
An error raised when wImage creation or operation failure.

Consts

wImageQualityNearest = 5
wImageQualityBilinear = 6
wImageQualityBicubic = 7
wImageQualityNormal = 0
wImageQualityHigh = 2
wImageQualityLow = 1
wImageRotateNoneFlipNone = 0
wImageRotateNoneFlipX = 4
wImageRotateNoneFlipY = 6
wImageRotateNoneFlipXY = 2
wImageRotate90FlipNone = 1
wImageRotate90FlipX = 5
wImageRotate90FlipY = 7
wImageRotate90FlipXY = 3
wImageRotate180FlipNone = 2
wImageRotate180FlipX = 6
wImageRotate180FlipY = 4
wImageRotate180FlipXY = 0
wImageRotate270FlipNone = 3
wImageRotate270FlipX = 7
wImageRotate270FlipY = 5
wImageRotate270FlipXY = 1
wIMAGE_TYPE_BMP = "BMP"
wIMAGE_TYPE_GIF = "GIF"
wIMAGE_TYPE_JPEG = "JPG"
wIMAGE_TYPE_PNG = "PNG"
wIMAGE_TYPE_TIFF = "TIF"
wIMAGE_TYPE_ICO = "ICO"
wBITMAP_TYPE_BMP = "BMP"
wBITMAP_TYPE_GIF = "GIF"
wBITMAP_TYPE_JPEG = "JPG"
wBITMAP_TYPE_PNG = "PNG"
wBITMAP_TYPE_TIFF = "TIF"
wBITMAP_TYPE_ICO = "ICO"

Procs

proc delete(self: wImage) {...}{.validate, raises: [], tags: [].}
Nim's garbage collector will delete this object by default. However, sometimes you maybe want do that by yourself.
proc getHandle(self: wImage): ptr GpBitmap {...}{.validate, property, inline, raises: [],
                                        tags: [].}
Gets the real resource handle of gdiplus bitmap.
proc getWidth(self: wImage): int {...}{.validate, property, raises: [], tags: [].}
Gets the width of the image in pixels.
proc getHeight(self: wImage): int {...}{.validate, property, raises: [], tags: [].}
Gets the height of the image in pixels.
proc getSize(self: wImage): wSize {...}{.validate, property, inline, raises: [], tags: [].}
Returns the size of the image in pixels.
proc getPixel(self: wImage; x: int; y: int): ARGB {...}{.validate, property, raises: [], tags: [].}
Return the ARGB value at given pixel location.
proc getPixel(self: wImage; pos: wPoint): ARGB {...}{.validate, property, raises: [], tags: [].}
Return the ARGB value at given pixel location.
proc setPixel(self: wImage; x: int; y: int; color: ARGB) {...}{.validate, property, raises: [],
    tags: [].}
Set the ARGB value at given pixel location.
proc setPixel(self: wImage; pos: wPoint; color: ARGB) {...}{.validate, property, raises: [],
    tags: [].}
Set the ARGB value at given pixel location.
proc getRed(self: wImage; x: int; y: int): byte {...}{.validate, property, raises: [], tags: [].}
Returns the red intensity at the given coordinate.
proc getRed(self: wImage; pos: wPoint): byte {...}{.validate, property, raises: [], tags: [].}
Returns the red intensity at the given coordinate.
proc getGreen(self: wImage; x: int; y: int): byte {...}{.validate, property, raises: [], tags: [].}
Returns the green intensity at the given coordinate.
proc getGreen(self: wImage; pos: wPoint): byte {...}{.validate, property, raises: [], tags: [].}
Returns the green intensity at the given coordinate.
proc getBlue(self: wImage; x: int; y: int): byte {...}{.validate, property, raises: [], tags: [].}
Returns the blue intensity at the given coordinate.
proc getBlue(self: wImage; pos: wPoint): byte {...}{.validate, property, raises: [], tags: [].}
Returns the blue intensity at the given coordinate.
proc getAlpha(self: wImage; x: int; y: int): byte {...}{.validate, property, raises: [], tags: [].}
Return alpha value at given pixel location.
proc getAlpha(self: wImage; pos: wPoint): byte {...}{.validate, property, raises: [], tags: [].}
Return alpha value at given pixel location.
proc saveFile(self: wImage; filename: string; fileType = "";
             quality: range[0 .. 100] = 90) {...}{.validate, raises: [], tags: [].}
Saves an image into the file. If fileType is empty, use extension name as fileType. Use getEncoders iterator to list the supported format.
proc saveData(self: wImage; fileType: string; quality: range[0 .. 100] = 90): string {...}{.
    validate, raises: [], tags: [].}
Saves an image into binary data (stored as string). Use getEncoders iterator to list the supported format.
proc final(self: wImage) {...}{.raises: [], tags: [].}
Default finalizer for wImage.
proc init(self: wImage; gdip: ptr GpBitmap; copy = true) {...}{.validate, raises: [], tags: [].}
Initializer.
proc Image(gdip: ptr GpBitmap; copy = true): wImage {...}{.inline, raises: [], tags: [].}
Creates an image from a gdiplus bitmap handle. If copy is false, this only wrap it to wImage object. It means the handle will be destroyed by wImage when it is destroyed.
proc init(self: wImage; image: wImage) {...}{.validate, inline, raises: [], tags: [].}
Initializer.
proc Image(image: wImage): wImage {...}{.inline, raises: [], tags: [].}
Creates an image from wImage object, aka. copy constructors.
proc init(self: wImage; bmp: wBitmap) {...}{.validate, raises: [], tags: [].}
Initializer.
proc Image(bmp: wBitmap): wImage {...}{.inline, raises: [], tags: [].}
Creates an image from wBitmap object.
proc init(self: wImage; data: pointer; length: int) {...}{.validate, raises: [], tags: [].}
Initializer.
proc Image(data: pointer; length: int): wImage {...}{.inline, raises: [], tags: [].}
Creates an image from binary image data. Use getDecoders iterator to list the supported format.
proc init(self: wImage; str: string) {...}{.validate, raises: [], tags: [].}
Initializer.
proc Image(str: string): wImage {...}{.inline, raises: [], tags: [].}
Creates an image from a file. Use getDecoders iterator to list the supported format. If str is not a valid file path, it will be regarded as the binary data in memory. For example:
const data = staticRead("test.png")
var image = Image(data)
proc init(self: wImage; width: int; height: int) {...}{.validate, raises: [], tags: [].}
Initializer.
proc Image(width: int; height: int): wImage {...}{.inline, raises: [], tags: [].}
Creates an empty image with the given size.
proc init(self: wImage; size: wSize) {...}{.validate, inline, raises: [], tags: [].}
Initializer.
proc Image(size: wSize): wImage {...}{.inline, raises: [], tags: [].}
Creates an empty image with the given size.
proc init(self: wImage; iconImage: wIconImage) {...}{.validate, raises: [], tags: [].}
Initializer.
proc Image(iconImage: wIconImage): wImage {...}{.inline, raises: [], tags: [].}
Creates an image from a wIconImage object.
proc init(self: wImage; icon: wIcon) {...}{.validate, raises: [], tags: [].}
Initializer.
proc Image(icon: wIcon): wImage {...}{.inline, raises: [], tags: [].}
Creates an image from wIcon object.
proc init(self: wImage; cursor: wCursor) {...}{.validate, raises: [], tags: [].}
Initializer.
proc Image(cursor: wCursor): wImage {...}{.inline, raises: [], tags: [].}
Creates an image from wCursor object.
proc scale(self: wImage; width, height: int; quality = wImageQualityNormal): wImage {...}{.
    validate, raises: [], tags: [].}
Returns a scaled version of the image.
proc scale(self: wImage; size: wSize; quality = wImageQualityNormal): wImage {...}{.validate,
    inline, raises: [], tags: [].}
Returns a scaled version of the image.
proc rescale(self: wImage; width, height: int; quality = wImageQualityNormal) {...}{.validate,
    discardable, raises: [], tags: [].}
Changes the size of the image in-place by scaling it.
proc rescale(self: wImage; size: wSize; quality = wImageQualityNormal) {...}{.validate,
    inline, discardable, raises: [], tags: [].}
Changes the size of the image in-place by scaling it. Returns a resized version of this image without scaling it. The image is pasted into a new image at the position pos or by given align. align can be combine of wRight, wCenter, wLeft, wUp, wMiddle, wDown.
proc size(self: wImage; width, height: int; x, y: int = 0; align = 0): wImage {...}{.validate,
    inline, raises: [], tags: [].}
Returns a resized version of this image without scaling it. Changes the size of the image in-place without scaling it.
proc resize(self: wImage; width, height: int; x, y: int = 0; align = 0) {...}{.validate,
    discardable, raises: [], tags: [].}
Changes the size of the image in-place without scaling it.
proc transform(self: wImage; scaleX, scaleY: float = 1;
              angle, deltaX, deltaY: float = 0; quality = wImageQualityNormal): wImage {...}{.
    validate, raises: [], tags: [].}
Returned a transformed version of this image by given parameters.
proc retransform(self: wImage; scaleX, scaleY: float = 1;
                angle, deltaX, deltaY: float = 0; quality = wImageQualityNormal) {...}{.
    validate, discardable, raises: [], tags: [].}
Transforms the image in-place.
proc paste(self: wImage; image: wImage; x, y: int = 0; align = 0) {...}{.validate, discardable,
    raises: [], tags: [].}
Copy the data of the given image to the specified position in this image.
proc paste(self: wImage; image: wImage; pos: wPoint; align = 0) {...}{.validate, discardable,
    raises: [], tags: [].}
Copy the data of the given image to the specified position in this image.
proc rotateFlip(self: wImage; flag: int) {...}{.validate, discardable, raises: [], tags: [].}
Rotates or flip the image.
proc rotateFlip(self: wImage; angle: int; flipX: bool; flipY: bool) {...}{.validate,
    discardable, raises: [], tags: [].}
Rotates or flip the image. Angle should be one of 0, 90, 180, 270.
proc getSubImage(self: wImage; rect: wRect): wImage {...}{.validate, raises: [], tags: [].}
Returns a sub image of the current one as long as the rect belongs entirely to the image.
proc crop(self: wImage; x, y, width, height: int): wImage {...}{.validate, raises: [], tags: [].}
Returns a cropped image of the current one as long as the rect belongs entirely to the image.
proc blur(self: wImage; radius: range[0 .. 255] = 0; expandEdge = true) {...}{.validate,
    raises: [], tags: [].}
Blur effect (Windows Vista or later).
proc brightnessContrast(self: wImage; brightness: range[-255 .. 255] = 0;
                       contrast: range[-100 .. 100] = 0) {...}{.validate, raises: [], tags: [].}
Brightness or contrast adjustment (Windows Vista or later).
proc sharpen(self: wImage; radius: range[0 .. 255] = 0; amount: range[0 .. 100] = 0) {...}{.
    validate, raises: [], tags: [].}
Sharpen effect (Windows Vista or later).
proc tint(self: wImage; hue: range[-180 .. 180] = 0; amount: range[0 .. 100] = 0) {...}{.validate,
    raises: [], tags: [].}
Tint effect (Windows Vista or later).
proc hueSaturationLightness(self: wImage; hue: range[-180 .. 180] = 0;
                           saturation: range[-100 .. 100] = 0;
                           lightness: range[-100 .. 100] = 0) {...}{.validate, raises: [],
    tags: [].}
Hue, saturation, or lightness adjustment (Windows Vista or later).
proc colorBalance(self: wImage; cyanRed: range[-100 .. 100] = 0;
                 magentaGreen: range[-100 .. 100] = 0;
                 yellowBlue: range[-100 .. 100] = 0) {...}{.validate, raises: [], tags: [].}
Color balance adjustment (Windows Vista or later).
proc levels(self: wImage; highlight: range[0 .. 100] = 0;
           midtone: range[-100 .. 100] = 0; shadow: range[0 .. 100] = 0) {...}{.validate,
    raises: [], tags: [].}
Light, midtone, or dark adjustment (Windows Vista or later).

Iterators

iterator getEncoders(self: wImage): string {...}{.validate, raises: [], tags: [].}
Iterates over each available image encoder on system.
iterator getDecoders(self: wImage): string {...}{.validate, raises: [], tags: [].}
Iterates over each available image decoder on system.