Bitmap

smile.pictures.Bitmap
See theBitmap companion object
final class Bitmap extends Element

A raster image, which is pixels, or a picture rendered when its pixels are asked for, placed in the world by an affine.

Its local frame is where its source lays its pixels, and its bounds are the box around those pixels under its affine. A bitmap turned by 45 degrees is as wide as its turned corners. The bitmap's own turns, flips and scalings, and its own crop and wrapShift, are also recorded as steps of its source, so that its pixels at one buffer pixel per logical pixel are the ones the buffer algorithms give, and a Stepwise output and a recoloring can replay them. Consecutive turns fold into one step by their total angle and crops into one crop, so a bitmap turned on every tick keeps one step. A transform no step can express, such as a scaling to less than a pixel, only composes into the affine, and so does a transform of a picture the bitmap is in.

Its anchor starts in the middle of its pixels. Its own crop is anchored in the middle of the crop, as a crop of any element is, and its flips and shifts keep its anchor. A crop that is not on whole pixels of the bitmap is the generic crop, a clip of the rectangle over the bitmap, and only a crop with no width or no height is blank space, as for any element.

Bitmaps are equal when they have the same source, the same affine and the same anchor, so two bitmaps of the same pixels made separately are not equal, and neither is a bitmap and the same bitmap scaled or flipped and back. Turns that add up to none give back the source from before them, so a bitmap turned and turned back is the bitmap it was.

smile.pictures.Bitmap$ builds bitmaps.

Attributes

Companion
object
Source
Element.scala
Graph
Supertypes
trait Element
class Object
trait Matchable
class Any

Members list

Grouped members

scaling

final def scaleAround(horizontal: Double, vertical: Double, pivot: Pos): Element

This element scaled by horizontal along the world's x axis and vertical along its y axis, around pivot. A negative factor also mirrors it on that axis, and a zero factor gives the empty picture.

This element scaled by horizontal along the world's x axis and vertical along its y axis, around pivot. A negative factor also mirrors it on that axis, and a zero factor gives the empty picture.

Attributes

Throws
IllegalArgumentException

if a factor or a coordinate of pivot is not finite, or the scaled element would be too large for its transform to hold in a Double

Inherited from:
Element
Source
Element.scala
final def scaleAround(factor: Double, pivot: Pos): Element

This element scaled by factor around pivot. A negative factor also mirrors it, and a zero factor gives the empty picture.

This element scaled by factor around pivot. A negative factor also mirrors it, and a zero factor gives the empty picture.

Attributes

Throws
IllegalArgumentException

if the factor or a coordinate of pivot is not finite, or the scaled element would be too large for its transform to hold in a Double

Inherited from:
Element
Source
Element.scala
final def scaleBy(horizontal: Double, vertical: Double): Element

This element scaled by horizontal along the world's x axis and vertical along its y axis, around its anchor. A negative factor also mirrors it on that axis, and a zero factor gives the empty picture.

This element scaled by horizontal along the world's x axis and vertical along its y axis, around its anchor. A negative factor also mirrors it on that axis, and a zero factor gives the empty picture.

import smile.colors.PresetColor.*
import smile.modeling.*

val coin      = Circle(Pos.Origin, 30, fillWith(Gold), lineWith(Black, 4, round = true))
val stretched = coin.scaleBy(2, 0.5)

A golden circle with a black outline The circle stretched wide and
flat, its outline thicker at the sides

Attributes

Throws
IllegalArgumentException

if a factor is not finite

Inherited from:
Element
Source
Element.scala
final def scaleBy(factor: Double): Element

This element scaled by factor around its anchor. A negative factor also mirrors it, and a zero factor gives the empty picture.

This element scaled by factor around its anchor. A negative factor also mirrors it, and a zero factor gives the empty picture.

Attributes

Throws
IllegalArgumentException

if the factor is not finite

Inherited from:
Element
Source
Element.scala
final def scaleTo(width: Double, height: Double): Element

This element scaled around its anchor along the world axes so that its bounds are width wide and height high, outlines included, since they scale with the shape.

This element scaled around its anchor along the world axes so that its bounds are width wide and height high, outlines included, since they scale with the shape.

A negative target flips the element on that axis first. A zero target gives the empty picture. An axis on which the element has no extent, such as the width of an empty text, is left as it is.

Scaling along the world axes scales the bounds by exactly the same factors, so one step is enough, up to the rounding of the factors and of the arithmetic that places the bounds. That rounding has an absolute floor of about 2^-19 pixel, since the anchor and every move lie on the grid of 2^-20 pixel, so a target smaller than that is not met to its own precision.

Attributes

Throws
IllegalArgumentException

if a target is not finite, or the target is so much larger than the current extent that the factor between them, or the scaled transform, overflows a Double

Inherited from:
Element
Source
Element.scala

turning

final def flipDiagonally: Self

This element mirrored both ways through its anchor, which is a half turn around it.

This element mirrored both ways through its anchor, which is a half turn around it.

Attributes

Inherited from:
Element
Source
Element.scala
final def flipHorizontally: Self

This element mirrored left to right across the vertical line through its anchor.

This element mirrored left to right across the vertical line through its anchor.

Attributes

Inherited from:
Element
Source
Element.scala
final def flipVertically: Self

This element mirrored top to bottom across the horizontal line through its anchor.

This element mirrored top to bottom across the horizontal line through its anchor.

Attributes

Inherited from:
Element
Source
Element.scala
final def rotateAround(degrees: Double, pivot: Pos): Self

This element turned by degrees around pivot, counterclockwise on screen for a positive angle. Right angles are exact.

This element turned by degrees around pivot, counterclockwise on screen for a positive angle. Right angles are exact.

import smile.colors.PresetColor.*
import smile.modeling.*

val hand = Rectangle(60, 8, fillWith(Navy), None)
val fan  = Picture((0 to 150 by 30).map(angle => hand.rotateAround(angle, Pos(-30, 0)))*)

Six bars fanning out counterclockwise from one end

Attributes

Throws
IllegalArgumentException

if the angle or a coordinate of pivot is not finite

Inherited from:
Element
Source
Element.scala
final def rotateBy(degrees: Double): Self

This element turned by degrees around its anchor, counterclockwise on screen for a positive angle. Right angles are exact.

This element turned by degrees around its anchor, counterclockwise on screen for a positive angle. Right angles are exact.

Attributes

Throws
IllegalArgumentException

if the angle is not finite

Inherited from:
Element
Source
Element.scala

measuring

final def anchor: Pos

The point this element is placed, turned and scaled by.

The point this element is placed, turned and scaled by.

Attributes

Inherited from:
Element
Source
Element.scala
final def bounds: Option[Bounds]

The tight box around what this element draws, outlines included, or None when it draws nothing and takes no room.

The tight box around what this element draws, outlines included, or None when it draws nothing and takes no room.

Attributes

Inherited from:
Element
Source
Element.scala
final def height: Double

The height of smile.pictures.Element.bounds in pixels, or 0 when there are none.

The height of smile.pictures.Element.bounds in pixels, or 0 when there are none.

Attributes

Inherited from:
Element
Source
Element.scala
final def width: Double

The width of smile.pictures.Element.bounds in pixels, or 0 when there are none.

The width of smile.pictures.Element.bounds in pixels, or 0 when there are none.

Attributes

Inherited from:
Element
Source
Element.scala

moving

final def moveBy(dx: Double, dy: Double): Self

This element moved by dx to the right and dy down.

This element moved by dx to the right and dy down.

Attributes

Throws
IllegalArgumentException

if an offset is not finite

Inherited from:
Element
Source
Element.scala
final def moveTo(p: Pos): Self

This element moved so that its anchor is at p.

This element moved so that its anchor is at p.

Attributes

Throws
IllegalArgumentException

if a coordinate of p is not finite

Inherited from:
Element
Source
Element.scala
final def withAnchor(p: Pos): Self

This element with its anchor at p, drawn exactly as before. The anchor goes to the nearest multiple of 2^-20 pixel, where every translation lies, so that quarter turns around it stay exact. Every transform puts the anchor back on that grid, which moves it by at most half a step.

This element with its anchor at p, drawn exactly as before. The anchor goes to the nearest multiple of 2^-20 pixel, where every translation lies, so that quarter turns around it stay exact. Every transform puts the anchor back on that grid, which moves it by at most half a step.

Attributes

Throws
IllegalArgumentException

if a coordinate of p is not finite

Inherited from:
Element
Source
Element.scala

Type members

Types

type Self = Bitmap

The type of element that a transform that keeps an element whole returns.

The type of element that a transform that keeps an element whole returns.

Attributes

Source
Element.scala

Value members

Concrete methods

def colorAt(x: Int, y: Int, settings: RenderSettings = ...): Option[Color]

The color of the pixel at column x and row y of smile.pictures.Bitmap.pixels for settings, or None outside them.

The color of the pixel at column x and row y of smile.pictures.Bitmap.pixels for settings, or None outside them.

Attributes

Source
Element.scala
def crop(world: Bounds): Element

This bitmap cropped to the world rectangle world, with the bounds and the anchor of any element's crop, which are the rectangle, anchored in its middle. Where the rectangle lies on whole pixels of this bitmap, which only its own operations have placed, the result is a smile.pictures.Bitmap that records the crop, so that its pixels are exactly the ones cropped and a crop of a crop is one crop. Otherwise it is the generic crop (see smile.pictures.crop), a clip of the rectangle over this bitmap.

This bitmap cropped to the world rectangle world, with the bounds and the anchor of any element's crop, which are the rectangle, anchored in its middle. Where the rectangle lies on whole pixels of this bitmap, which only its own operations have placed, the result is a smile.pictures.Bitmap that records the crop, so that its pixels are exactly the ones cropped and a crop of a crop is one crop. Otherwise it is the generic crop (see smile.pictures.crop), a clip of the rectangle over this bitmap.

Attributes

Throws
IllegalArgumentException

if a corner of world is not finite

Source
Element.scala
override def equals(other: Any): Boolean

Compares the receiver object (this) with the argument object (that) for equivalence.

Compares the receiver object (this) with the argument object (that) for equivalence.

Any implementation of this method should be an equivalence relation:

  • It is reflexive: for any instance x of type Any, x.equals(x) should return true.
  • It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any instances x, y, and z of type Any if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is usually necessary to override hashCode to ensure that objects which are "equal" (o1.equals(o2) returns true) hash to the same scala.Int. (o1.hashCode.equals(o2.hashCode)).

Value parameters

that

the object to compare against this object for equality.

Attributes

Returns

true if the receiver object is equivalent to the argument; false otherwise.

Definition Classes
Object -> Any
Source
Element.scala
def getColor(x: Int, y: Int, settings: RenderSettings = ...): Color

The color of the pixel at column x and row y of smile.pictures.Bitmap.pixels for settings.

The color of the pixel at column x and row y of smile.pictures.Bitmap.pixels for settings.

Attributes

Source
Element.scala
def mergeARGBWith(another: Bitmap, pixelMerger: (Int, Int) => Int, settings: RenderSettings): Bitmap

This bitmap's pixels merged with those of another, as smile.pictures.Bitmap.mergeWith merges them, with a function on packed ARGB integers, which boxes no smile.colors.Color per pixel. The pixels of both are their smile.pictures.Bitmap.pixels for settings, and the merge runs at once.

This bitmap's pixels merged with those of another, as smile.pictures.Bitmap.mergeWith merges them, with a function on packed ARGB integers, which boxes no smile.colors.Color per pixel. The pixels of both are their smile.pictures.Bitmap.pixels for settings, and the merge runs at once.

Attributes

Source
Element.scala
def mergeWith(another: Bitmap, pixelMerger: (Color, Color) => Color, settings: RenderSettings): Bitmap

This bitmap's pixels merged with those of another, pixel by pixel with pixelMerger, from the upper left corners of both, over as many pixels as both have, as smile.pictures.Bitmap.mergeARGBWith merges them.

This bitmap's pixels merged with those of another, pixel by pixel with pixelMerger, from the upper left corners of both, over as many pixels as both have, as smile.pictures.Bitmap.mergeARGBWith merges them.

Attributes

Source
Element.scala
def pixels(settings: RenderSettings = ...): Pixels

This bitmap's pixels at one buffer pixel per logical pixel, computed with settings at this call, as a read-only view.

This bitmap's pixels at one buffer pixel per logical pixel, computed with settings at this call, as a read-only view.

While this bitmap's transform only moves it, which covers every transform of its own that a step records, they are the pixels smile.pictures.PixelSource.buffer gives for its source. A transform no step expresses, such as a scaling to less than a pixel or a transform of a picture it was in, is drawn through the shared draw plan instead, and the pixels are the whole pixels covering this bitmap's bounds. Those are rendered once for the last settings asked for.

Attributes

Source
Element.scala

How this bitmap would like to be resampled where an output in Direct mode draws it at another size than its pixels'. A Stepwise output ignores it. See smile.pictures.ResamplingHint.

How this bitmap would like to be resampled where an output in Direct mode draws it at another size than its pixels'. A Stepwise output ignores it. See smile.pictures.ResamplingHint.

Attributes

Source
Element.scala
def saveAsPngTo(path: String, settings: RenderSettings = ...): Boolean

Saves this bitmap's pixels for settings as a PNG image at path, and tells whether that worked. Only the JVM can save files. In a browser, this always gives false.

Saves this bitmap's pixels for settings as a PNG image at path, and tells whether that worked. Only the JVM can save files. In a browser, this always gives false.

Attributes

Source
Element.scala
def setColorsByLocation(generator: (Int, Int) => Color): Bitmap

This bitmap with the color of each pixel given by generator from its column and row.

This bitmap with the color of each pixel given by generator from its column and row.

Attributes

Source
Element.scala
def toAWTImage(settings: RenderSettings = ...): BufferedImage
Extension method from smile.pictures

This bitmap's pixels as a new TYPE_INT_ARGB BufferedImage of the bitmap's size. JVM only.

This bitmap's pixels as a new TYPE_INT_ARGB BufferedImage of the bitmap's size. JVM only.

The image is a copy. Drawing into it leaves the bitmap unchanged, as an immutable Bitmap requires. It copies the packed ARGB values, because drawing the bitmap would drop the color of fully transparent pixels. A BufferedImage is also a java.awt.Image.

Value parameters

settings

The settings the bitmap's pixels are computed with. See smile.pictures.Bitmap.pixels.

Attributes

Source
JVMBitmapConversions.scala
def toCanvas(settings: RenderSettings = ...): Canvas
Extension method from smile.pictures

This bitmap's pixels on a new canvas of the bitmap's size. Scala.js only.

This bitmap's pixels on a new canvas of the bitmap's size. Scala.js only.

Every call makes a new canvas with a copy of the pixels. Drawing on it leaves the bitmap unchanged, as an immutable Bitmap requires. A canvas premultiplies its pixels by their alpha, so the colors of translucent pixels read back from it may come back slightly changed.

Value parameters

settings

The settings the bitmap's pixels are computed with. See smile.pictures.Bitmap.pixels.

Attributes

Source
JSBitmapConversions.scala
override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Any
Source
Element.scala
def toSwingIcon(settings: RenderSettings = ...): ImageIcon
Extension method from smile.pictures

This bitmap as a Swing ImageIcon the size of the bitmap, painting a copy of its pixels. JVM only. See smile.pictures.toAWTImage.

This bitmap as a Swing ImageIcon the size of the bitmap, painting a copy of its pixels. JVM only. See smile.pictures.toAWTImage.

Attributes

Source
JVMBitmapConversions.scala
def transformARGB(transformer: Int => Int, settings: RenderSettings): Bitmap

This bitmap with each pixel replaced by what transformer gives for it as a packed ARGB integer, which boxes no smile.colors.Color per pixel. The pixels are this bitmap's smile.pictures.Bitmap.pixels for settings, and the function runs at once, once per pixel, row by row.

This bitmap with each pixel replaced by what transformer gives for it as a packed ARGB integer, which boxes no smile.colors.Color per pixel. The pixels are this bitmap's smile.pictures.Bitmap.pixels for settings, and the function runs at once, once per pixel, row by row.

Attributes

Source
Element.scala
def transformColorToColor(transformer: Color => Color, settings: RenderSettings): Bitmap

This bitmap with each pixel's color replaced by what transformer gives for it, from the pixels for settings, as smile.pictures.Bitmap.transformARGB transforms them.

This bitmap with each pixel's color replaced by what transformer gives for it, from the pixels for settings, as smile.pictures.Bitmap.transformARGB transforms them.

Attributes

Source
Element.scala

This bitmap with another resampling hint. Pixelated draws nearest neighbor and Smooth bilinear in Direct mode, whatever the settings say, and Auto follows the settings' bufferScalingMethod. The pixels of a Stepwise output are the same for every hint, and the bitmap's own operations keep the hint.

This bitmap with another resampling hint. Pixelated draws nearest neighbor and Smooth bilinear in Direct mode, whatever the settings say, and Auto follows the settings' bufferScalingMethod. The pixels of a Stepwise output are the same for every hint, and the bitmap's own operations keep the hint.

Attributes

Source
Element.scala
def wrapShift(dx: Int, dy: Int): Element

This bitmap's content moved right by dx and down by dy with wraparound, as the generic wrapShift of smile.pictures moves it. The bounds and the anchor stay where they are. Where this bitmap has one pixel per logical pixel on whole logical pixels, and only its own operations have placed it, the shift is recorded on its pixels, shifts in a row fold into one, and the result is a smile.pictures.Bitmap. Otherwise it is the generic wrap shift.

This bitmap's content moved right by dx and down by dy with wraparound, as the generic wrapShift of smile.pictures moves it. The bounds and the anchor stay where they are. Where this bitmap has one pixel per logical pixel on whole logical pixels, and only its own operations have placed it, the shift is recorded on its pixels, shifts in a row fold into one, and the result is a smile.pictures.Bitmap. Otherwise it is the generic wrap shift.

Attributes

Source
Element.scala

Concrete fields

lazy override val hashCode: Int

Calculates a hash code value for the object.

Calculates a hash code value for the object.

The default hashing algorithm is platform dependent.

Note that it is allowed for two objects to have identical hash codes (o1.hashCode.equals(o2.hashCode)) yet not be equal (o1.equals(o2) returns false). A degenerate implementation could always return 0. However, it is required that if two objects are equal (o1.equals(o2) returns true) that they have identical hash codes (o1.hashCode.equals(o2.hashCode)). Therefore, when overriding this method, be sure to verify that the behavior is consistent with the equals method.

Attributes

Returns

the hash code value for this object.

Source
Element.scala