Skip to content
FutureBlitz

    Install

    Import std.image.image

    std.image.image

    Image: a picture's pixels, in rows from the top, each RGBA, 8 bits a channel, its alpha straight, in a Buffer<UInt8>, which C code can read and write through its Pointer, and which the formats' Decodes give and their Encodes take. Image.Decode reads any format std.image knows, by how its bytes start, but HDR's, whose pixels are an HdrImage's, and Image.Load a file of one. Its transforms, Resize, Crop, the flips and turns, Draw, Paste, and Fill, change it in place.

    std/image/image.fb

    Types

    ImageFormat enum

    Public Enum ImageFormat

    The formats std.image reads, which Image.FormatOf tells apart.

    std/image/image.fb, line 16

    • PNG enum member #

      PNG.

    • JPEG enum member #

      JPEG.

    • BMP enum member #

      Windows's BMP.

    • TGA enum member #

      Truevision's TGA.

    • GIF enum member #

      GIF, its first frame.

    • HDR enum member #

      Radiance's HDR.

    • QOI enum member #

      QOI, the Quite OK Image format.

    • WEBP enum member #

      WebP.

    ResizeFilter enum

    Public Enum ResizeFilter

    How Resize gives a pixel the colors of those under it, as Pillow resamples, the filter widened as the image shrinks.

    std/image/image.fb, line 37

    • NEAREST enum member #

      The nearest one's.

    • BOX enum member #

      A box's weighted sum, the average of what shrinks into a pixel.

    • BILINEAR enum member #

      A triangle's weighted sum.

    • BICUBIC enum member #

      Keys's cubic's weighted sum.

    • LANCZOS enum member #

      Lanczos's 3 lobes' weighted sum, the sharpest.

    Image class

    Public Class Image

    A picture's pixels, in rows from the top, each RGBA, 8 bits a channel, its alpha straight.

    std/image/image.fb, line 51

    • @PanicsAtCaller Public New(width: Int, height: Int) constructor #

      An image of width by height pixels, each transparent black. Panics when either is negative, or there'd be more pixels than an Image holds, 536870911.

    • @PanicsAtCaller Public Static Method FromBytes(width: Int, height: Int, bytes: UInt8[]): Image static method #

      An image of width by height pixels whose bytes, 4 for each pixel, red, green, blue, and alpha, are a copy of bytes. Panics when there aren't that many, or the size is one New panics for.

    • @PanicsAtCaller Public Static Method Over(width: Int, height: Int, pixels: Buffer<UInt8>): Image static method #

      An image of width by height pixels whose bytes, 4 for each pixel, red, green, blue, and alpha, are the Buffer's own, not a copy: what changes in one changes in the other, until a transform gives the image new ones. Panics when the Buffer doesn't have that many, or the size is one New panics for.

    • Public Property Pixels: Buffer<UInt8> property #

      Its pixels' bytes, 4 for each, red, green, blue, and alpha, in rows from the top: the image's own, not a copy, which C code can read and write through its Pointer. Resize, Crop, and the flips and turns give it new ones, which a Buffer from before doesn't see.

    • Public Property Width: Int property #

      How many pixels wide it is.

    • Public Property Height: Int property #

      How many pixels high it is.

    • @PanicsAtCaller Operator [](x: Int, y: Int): Color32 operator #

      The pixel x from the left and y from the top. Panics when it's outside the image.

    • @PanicsAtCaller Operator []=(x: Int, y: Int, color: Color32) operator #

      Gives the pixel x from the left and y from the top a color. Panics when it's outside the image.

    • Public Method ToBytes(): UInt8[] method #

      A copy of its pixels' bytes, 4 for each, red, green, blue, and alpha.

    • Public Method Clone(): Image method #

      A new image of the same pixels, in a Buffer of its own.

    • @PanicsAtCaller Public Static Method Decode(data: UInt8[], limit: Int = MOST_PIXELS): Image Throws IOError static method #

      The image in data, a PNG, JPEG, BMP, TGA, GIF's first frame, QOI, or WebP, by how its bytes start. Throws an IOError of INVALID_DATA when they're none of those, or broken, UNEXPECTED_END when they end too soon, and OTHER when they're an HDR image, which Hdr.Decode reads, or use what isn't supported, or the image has more pixels than limit. Panics when the limit is negative.

    • @PanicsAtCaller Public Static Method Load(path: Path, limit: Int = MOST_PIXELS): Image Throws IOError static method #

      The image in the file at path, which Decode reads from its bytes. Throws the IOError File.ReadBytes does for a file that can't be read, and Decode's, its Path the file's, for one it can't read an image of. Panics when the limit is negative.

    • @PanicsAtCaller Public Static Async Method LoadAsync(path: Path, limit: Int = MOST_PIXELS): Image Throws IOError static method #

      Load's Async twin, which reads the file on libuv's thread pool while the thread that called it goes on, and decodes it there once the Await resumes.

    • Public Static Method FormatOf(data: UInt8[]): ImageFormat? static method #

      The format the data's bytes start as, or Null when they start as none of std.image's. A TGA has no signature, so it's what starts as a TGA's header does once no other format matches.

    • @PanicsAtCaller Public Method Resize(width: Int, height: Int, filter: ResizeFilter = ResizeFilter.LANCZOS) method #

      Makes it width by height pixels, each one the colors under it by the filter, weighted by their alpha, so a transparent pixel's color counts for nothing. Panics when the size is one New panics for, or the image has no pixels and the new size does.

    • @PanicsAtCaller Public Method Crop(x: Int, y: Int, width: Int, height: Int) method #

      Keeps only its width by height pixels from (x, y). Panics when they aren't all in it.

    • Public Method FlipHorizontal() method #

      Flips it across, so its left is its right.

    • Public Method FlipVertical() method #

      Flips it down, so its top is its bottom.

    • Public Method RotateClockwise() method #

      Turns it a quarter clockwise, so its height is its width.

    • Public Method RotateCounterclockwise() method #

      Turns it a quarter counterclockwise, so its height is its width.

    • Public Method Rotate180() method #

      Turns it a half.

    • Public Method Draw(image: Image, x: Int, y: Int) method #

      Draws image on it, its top-left pixel at (x, y), over these by its alpha, as "over" does with straight alpha; what falls outside is left out.

    • Public Method Paste(image: Image, x: Int, y: Int) method #

      Puts image's pixels in place of these, alpha too, its top-left pixel at (x, y); what falls outside is left out.

    • Public Method Fill(color: Color32) method #

      Gives every pixel the color.

    Report an issue with this page or with FutureBlitz on GitHub.