liveBook · Manning

Bitmap image

As explained in Learn Go with Pocket-Sized Projects

A bitmap image represents visual content as a grid of individually colored picture elements.

A bitmap image, also called a raster image, stores visual content as a two-dimensional grid of individually colored pixels. Zooming enlarges those pixels rather than preserving infinitely thin vector geometry. PNG and JPEG are common bitmap formats; JPEG saves space through lossy compression, while PNG preserves exact pixel values. section 9.1.1 section 9.7

Pixels can represent more than photographic color:

  • RGBA values can encode emitted red, green, and blue light plus transparency. section 9.7
  • Pixels can encode numerical data such as heat-map or tissue density values. section 9.1.1
  • Palettes can assign category meanings to colors, such as countries on a map. section 9.1.1
  • Scanning uses nested row-and-column loops; scanline order benefits performance. section 9.7

Exact pixels for a maze

A maze can use a PNG bitmap so wall, path, entrance, and treasure colors remain exact. In Go, decode the file with image/png, inspect pixels through Image.At or RGBAAt, compare known colors, and write pixels with RGBA.Set. section 9.1.1 section 9.7

> go doc image
package image // import "image"

[...]

type Image interface{ ... }
    func Decode(r io.Reader) (Image, string, error)

type Point struct{ ... }

type RGBA struct{ ... }
    func NewRGBA(r Rectangle) *RGBA

> go doc image.Point
type Point struct {
    X, Y int
}
    A Point is an X, Y coordinate pair. The axes increase right and down.

Go's image documentation exposes Image, Point, RGBA, decoding, and coordinate behavior; Point axes increase rightward and downward. section 9.1.1

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Defines grids, pixels, color meanings, formats, coordinate conventions, and Go pixel APIs, but not compression internals.
Examples
Uses PNG maze maps, heat maps, MRI tissue density, photographic color, and country-colored map palettes.
What you can do after
Operate Go's image APIs to decode, inspect, compare, scan, and modify bitmap pixels.
How it connects
Connects raster images with vector images, pixels, RGBA, PNG, JPEG, palettes, image decoding, and coordinate systems.

Also explained in

Compare how 4 books explain bitmap image →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.