Skip to content
Educora
IntermediateGrades 8–1025 min12 / 59

Computer graphics: encoding raster and vector images

Raster and vector graphics, pixels, resolution, color depth and palette (N = 2ⁱ), High Color and True Color, the image size V = W · H · i, ratio problems, and the RGB and CMYK models — with solved DİM-style tasks.

Check yourself
In this lesson you will learn
  • Compare raster and vector images and recognize their formats and editors
  • Find the color depth from the palette (N = 2ⁱ) and the size of an image with V = W · H · i
  • Find how many times the size changes when the dimensions and palette change, and work back from a size to a palette or a dimension
  • Explain the RGB and CMYK color models

If you zoom far into a photo on your phone, it breaks into small colored squares. A website logo, however much you zoom, keeps smooth edges. The reason is that the photo is a raster image and the logo is usually a vector image: the first is made of dots, the second of formulas. In this lesson we will see how both are encoded and how to calculate the size of a raster image.

This lesson continues “Encoding text”: there every symbol was replaced by a code, here every pixel is. The topic is frequent in the entrance exam: in the four entrance exams of 2025–2026 there were 4 tasks on encoding graphics (a change of palette, matching volumes and palettes, High Color and True Color, an image whose width, height and palette change), and one more task needed the size of a picture in a document.

Raster and vector graphics

Definition
Raster image

A rectangular grid (raster) of small square dots — pixels. Every pixel has its own color, and the computer stores the color code of each pixel separately. Photos, scanned documents and screenshots are raster images.

Definition
Vector image

An image made of simple geometric objects — line segments, rectangles, ellipses, polygons and curves. The computer stores not dots but descriptions of the objects: coordinates, sizes, line thickness, color. Logos, diagrams, technical drawings and fonts are vector images.

RRaster image(pixels)Vector image(center and radius)
The same circle: the raster version stores every pixel, the vector version only the center, radius and color.
Raster graphicsVector graphics
Made ofpixelsgeometric objects (primitives)
When enlargedbecomes stepped, quality is lostno loss of quality
File size depends onthe number of pixels and the color depththe number and complexity of objects
Good forphotos, realistic pictureslogos, diagrams, drawings, fonts
FormatsBMP, JPEG, PNG, GIF, TIFFSVG, AI, CDR, EPS
Graphics editorsPaint, Adobe Photoshop, GIMPCorelDRAW, Adobe Illustrator, Inkscape
HTML
<svg width="240" height="120">
  <circle cx="60" cy="60" r="50" fill="red"/>
  <rect x="140" y="20" width="80" height="80" fill="royalblue"/>
</svg>
Preview
A vector image is a set of commands written as text: a red circle with center (60, 60) and radius 50, and an 80 × 80 square whose top-left corner is at (140, 20). Change r="50" and run the code again: the circle grows without losing quality.

Pixels, resolution, color depth and palette

Definition
Resolution

How many pixels an image (or a screen) has across and down: W × H. A 1920 × 1080 (Full HD) screen has 1920 · 1080 = 2,073,600 pixels. For printers and scanners, resolution is given in dots per inch (dpi).

Definition
Color depth

The number of bits i used to encode the color of one pixel. The palette is the set of colors (shades) an image can use; the number of colors in the palette is N = 2ⁱ.

N = 2ⁱ
where:
  • Nthe number of colors (shades) in the palette
  • icolor depth — the number of bits in the code of one pixel

If the palette is not a power of two, round i up: 100 colors need 7 bits (2⁷ = 128). DİM puts it this way: “each color is encoded with the smallest possible number of bits”.

ModeColor depth iPalette N = 2ⁱ
black and white1 bit2
16 colors4 bits16
256 colors8 bits256
High Color16 bits65,536
True Color24 bits (8 bits for each of R, G, B)16,777,216
The names High Color and True Color appear in the exam too: remember their number of bits (16 and 24). The modern 32-bit mode adds 8 bits of transparency to True Color.
Palette and color depth

1) A palette has 512 colors. What is the color depth?
2) An image uses 100 colors, and each color is encoded with the smallest possible number of bits. How many bits does one pixel take?
3) The color depth is 12 bits. At most how many colors can the palette have?
4) How many colors does High Color mode have?

Show solution
1) 512 = 2⁹ ⇒ i = 9 bits.
2) 2⁶ = 64 < 100 ≤ 128 = 2⁷ ⇒ 7 bits.
3) N = 2¹² = 4096 colors.
4) i = 16 ⇒ N = 2¹⁶ = 65,536 colors.

The size of a raster image: V = W · H · i

In a raster image the color of every pixel is written with i bits. There are W · H pixels, so the size of the image is the sum of all pixel codes. It is the “graphic version” of I = K · i: pixels take the place of symbols.

V = W · H · i
where:
  • Vthe information volume of the raster image (bits)
  • Wthe number of pixels across (width)
  • Hthe number of pixels down (height)
  • icolor depth (bits), N = 2ⁱ

First find i from the palette, then multiply and convert the bits into the unit you need: 2¹³ bits = 1 KB, 2²³ bits = 1 MB.

The size of an image

1) Find the size in KB of a 1024 × 768 image with 256 colors.
2) How many KB is a 640 × 480 image with 16 colors?
3) How many bytes does one frame take on a Full HD (1920 × 1080) screen in True Color mode?

Show solution
1) i = 8 bits (256 = 2⁸). V = 1024 · 768 · 8 bits = 2¹⁰ · 768 · 2³ bits; to get KB divide by 2¹³: V = 768 KB.
2) i = 4 bits. V = 640 · 480 · 4 = 1,228,800 bits = 153,600 bytes = 153,600 ÷ 1024 = 150 KB.
3) i = 24 bits = 3 bytes. V = 1920 · 1080 · 3 = 6,220,800 bytes ≈ 5.93 MB.
Working backwards

1) A 512 × 256 image takes 96 KB. At most how many colors are in its palette?
2) A 16-color image takes 256 KB and is 1024 pixels wide. How many pixels high is it?

Show solution
1) Pixels: 2⁹ · 2⁸ = 2¹⁷; V = 96 · 2¹³ bits.
i = 96 · 2¹³ ÷ 2¹⁷ = 96 ÷ 16 = 6 bits ⇒ N = 2⁶ = 64 colors.
2) i = 4 bits; V = 256 · 2¹³ = 2²¹ bits.
H = V ÷ (W · i) = 2²¹ ÷ (2¹⁰ · 2²) = 2⁹ = 512 pixels.
Matching: volume and palette

Match the items (x is the color depth).
Size of the image:
1. 1024 × 512 × x bits = 640 KB
2. 256 × 256 × x bits = 3 · 2¹⁷ bits
3. 512 × 128 × x bits = 112 KB
Largest number of colors in the palette:
a. 2¹⁰
b. 2⁶
c. 2¹⁴
d. 10
e. 64

Show solution
1. 640 KB = 640 · 2¹³ bits; x = 640 · 2¹³ ÷ 2¹⁹ = 640 ÷ 64 = 10 bits ⇒ N = 2¹⁰ ⇒ a.
2. x = 3 · 2¹⁷ ÷ 2¹⁶ = 6 bits ⇒ N = 2⁶ = 64 ⇒ b, e.
3. x = 112 · 2¹³ ÷ 2¹⁶ = 112 ÷ 8 = 14 bits ⇒ N = 2¹⁴ ⇒ c.
d (10) is a color depth, not a number of colors — it is a trap.
Answer: 1 – a; 2 – b, e; 3 – c.
Text and pictures in a document

In a 24-page document, each of the first 8 pages holds only a 256 × 256 image encoded with a 16-color palette, and each of the other pages holds UNICODE text of 40 lines with 64 symbols per line. What is the information volume of the document in KB?
A) 296 B) 256 C) 336 D) 1104 E) 80

Show solution
Image: 256 · 256 · 4 bits = 2⁸ · 2⁸ · 2² = 2¹⁸ bits = 2¹⁸ ÷ 2¹³ = 32 KB; 8 images: 8 · 32 = 256 KB.
Text: 24 − 8 = 16 pages; 16 · 40 · 64 · 2 bytes = 81,920 bytes = 80 KB.
Total: 256 + 80 = 336 KB (C).
The traps: A — counting the text in ASCII (40 KB), B — forgetting the text, D — taking 16 colors as 16 bits, E — forgetting the images.
Python
import math

def image_kb(w, h, colors):
    i = math.ceil(math.log2(colors))   # color depth, bits
    return w * h * i / 2**13           # bits -> KB

print(image_kb(1024, 768, 256))
print(image_kb(640, 480, 16))
print(image_kb(512, 256, 64))
▸ Expected output
768.0
150.0
96.0
The function finds the color depth from the palette (math.ceil rounds up) and returns the size in KB. Put in your own numbers to check your answers.

Ratio problems: how many times does the size change?

Many tasks give not the image itself but how it changes: the palette shrinks, the width and height change. Then you do not need the full size — the ratio is enough, because the size is directly proportional to the width, the height and the color depth.

V₂ / V₁ = (W₂ / W₁) · (H₂ / H₁) · (i₂ / i₁)V₂ / V₁ = (W₂ / W₁) · (H₂ / H₁) · (i₂ / i₁)
where:
  • W₂ / W₁, H₂ / H₁W₂ / W₁, H₂ / H₁how many times the width and the height change
  • i₂ / i₁i₂ / i₁the ratio of color depths — not of palettes!

When the palette shrinks 2ᵏ times, the color depth drops by k bits, and the size falls i₁ / (i₁ − k) times, not 2ᵏ times.

The palette changes

1) An image has 65,536 colors in its palette. The number of colors is made 256 times smaller. How many times smaller does the image become? (Each color is encoded with the smallest possible number of bits.)
A) 256 B) 2 C) 8 D) 16 E) 128
2) A black-and-white (2-color) image is moved to a 256-color palette. How many times larger does it become?

Show solution
1) N₁ = 65,536 = 2¹⁶ ⇒ i₁ = 16 bits; N₂ = 2¹⁶ ÷ 2⁸ = 2⁸ ⇒ i₂ = 8 bits.
The number of pixels does not change: V₁ / V₂ = 16 / 8 = 2 (B). 256 (A) is the ratio of the palettes, not of the sizes.
2) i₁ = 1 bit, i₂ = 8 bits ⇒ the size grows 8 times.
Size and palette change together

A 256-color raster image takes 96 KB. Another image is twice as wide and 8 times shorter, and it uses a 65,536-color palette. Find its size in KB.

Show solution
i₁ = 8 bits, i₂ = 16 bits.
V₂ / V₁ = 2 · (1/8) · (16/8) = 2 · 1/8 · 2 = 1/2.
V₂ = 96 ÷ 2 = 48 KB.
Check with pixels: V₁ = A · 8 bits = 96 · 2¹³ bits ⇒ A = 96 · 2¹⁰ pixels; the new image has A · 2 ÷ 8 = 24 · 2¹⁰ pixels, V₂ = 24 · 2¹⁰ · 16 bits = 48 · 2¹³ bits = 48 KB.
Two images with the same number of pixels

Two images, one with 256 colors and one in True Color, have the same number of pixels. Together they take 96 MB. Find the size of the 256-color image in MB.
A) 12 B) 24 C) 48 D) 72 E) 32

Show solution
Let the number of pixels be a. i₁ = 8 bits, i₂ = 24 bits.
a · 8 + a · 24 = a · 32 bits = 96 · 2²³ bits ⇒ a = 3 · 2²³.
V₁ = 3 · 2²³ · 8 bits = 24 · 2²³ bits = 24 MB (B); the True Color image is 72 MB.
Shortcut: the sizes are proportional to the bits, 8 : 24 = 1 : 3, so 96 MB splits into 1 + 3 = 4 parts: 96 ÷ 4 = 24.

Color models: RGB and CMYK

A screen makes colors with light: every pixel consists of three tiny light sources — Red, Green and Blue. This is the RGB model. Adding colors makes them brighter (an additive model): all three at full power give white, none at all give black. In True Color each component is written with 8 bits (0–255), so a pixel is 3 · 8 = 24 bits.

A printer puts ink on white paper, and ink absorbs part of the light. That is why printing uses the CMYK model: Cyan, Magenta, Yellow and blacK (Key). Mixing inks makes the color darker (a subtractive model). Black ink is added separately because a mix of the three colored inks does not give a pure black, and it also saves ink when printing text.

Interactive
Loading simulation…
Mix the lights: red + green = yellow, all three = white. Switch to the subtractive mode to see how inks get darker.
RGB codes

1) What color is (0, 255, 0) in RGB?
2) What color is (255, 255, 0)?
3) What color do you get when the red, green and blue components are all 128?
4) Write the RGB code of white. How is white obtained in CMYK?

Show solution
1) Only green is at full power ⇒ green.
2) Red + green light ⇒ yellow; in hexadecimal it is #FFFF00.
3) When the three components are equal, the color is a shade between white and black; 128 is in the middle ⇒ gray.
4) RGB: (255, 255, 255). In CMYK no ink is put down for white: (0, 0, 0, 0) — the paper’s own color stays.

In the next lesson, “Encoding sound and video”, we will see how sound and video become digital codes; a video is really a sequence of raster images.

Key points

  • A raster image is made of pixels, a vector image of descriptions of geometric objects; a vector image keeps its quality when enlarged.
  • Palette N = 2ⁱ, where i is the color depth; i is rounded up (100 colors → 7 bits).
  • The size of a raster image is V = W · H · i; divide the bits by 2¹³ to get KB.
  • High Color is 16 bits, True Color 24 bits (8 bits for each of R, G, B).
  • In ratio problems use the ratio of bits, not of palettes: 65,536 → 256 colors = 16 → 8 bits, the size halves.
  • Screens use the RGB (additive) model, printers the CMYK (subtractive) model.

Check yourself

12 questions. Every correct answer earns XP.

1 / 12
Which of these is a vector graphics format?