1.2 Multimedia (3)
Resources |
Revision Questions |
Computer Science
Login to see all questions
Click on a question to view the answer
1.
Consider a simple SVG file representing a red circle with a radius of 50 pixels, positioned at coordinates (100, 100). Provide the SVG code for this circle, including the necessary tags and attributes. Explain the role of the `transform` attribute in modifying the position and size of the circle.
The SVG code for a red circle with a radius of 50 pixels, positioned at coordinates (100, 100) is:
<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
<circle cx="100" cy="100" r="50" fill="red">
</circle>
</svg>
Explanation:
<svg width="200" height="200" ...>
: Defines the SVG canvas with a width and height of 200 pixels. The xmlns
attribute specifies the XML namespace for SVG.<circle cx="100" cy="100" r="50" fill="red">
: Defines a circle element.cx="100"
: Specifies the x-coordinate of the circle's center as 100 pixels.cy="100"
: Specifies the y-coordinate of the circle's center as 100 pixels.r="50"
: Specifies the radius of the circle as 50 pixels.fill="red"
: Specifies the fill colour of the circle as red.
</circle>
: Closes the circle element.</svg>
: Closes the SVG element.
Role of the transform
attribute:
The transform
attribute allows you to apply transformations to SVG elements. It accepts a string of transformation commands, separated by spaces. These commands can include:
translate(x, y)
: Moves the element by x
pixels horizontally and y
pixels vertically. For example, transform="translate(50, 20)"
would move the circle 50 pixels to the right and 20 pixels down.rotate(angle)
: Rotates the element by angle
degrees. For example, transform="rotate(45)"
would rotate the circle 45 degrees around its center.scale(x, y)
: Scales the element by x
and y
factors. For example, transform="scale(2, 0.5)"
would scale the circle twice in the x direction and half in the y direction.skew(x, y)
: Skews the element by x
and y
degrees.- Combining Transformations: Multiple transformations can be combined in a single
transform
attribute. For example, transform="translate(50, 20) rotate(45)"
would first translate the circle and then rotate it.
2.
Consider a bitmap image where each pixel is represented by a byte. The image has a width of 256 pixels and a height of 256 pixels. What is the estimated file size of the image in megabytes (MB)? Show your working.
Understanding the Problem: The file size is determined by the image dimensions and the size of the pixel data. Each pixel is represented by a byte.
Calculations:
- Total number of pixels: Width x Height = 256 pixels x 256 pixels = 65536 pixels
- Total number of bytes required: Number of pixels x Bytes per pixel = 65536 pixels x 1 byte/pixel = 65536 bytes
- Convert bytes to kilobytes: 65536 bytes / 1024 bytes/KB = 64 KB
- Convert kilobytes to megabytes: 64 KB / 1024 KB/MB = 0.0625 MB
Answer: The estimated file size of the bitmap image is 0.0625 MB.
3.
Explain how applying image compression techniques, such as JPEG or PNG, affects both the file size and the visual quality of a bitmap image. Discuss the different compression methods used in JPEG and PNG and their respective advantages and disadvantages.
Image compression techniques are used to reduce the file size of bitmap images. This is achieved by removing redundant data or using mathematical algorithms to represent the image with fewer bits. However, compression often involves a trade-off between file size and visual quality.
JPEG Compression: JPEG (Joint Photographic Experts Group) is a lossy compression method. This means that some image data is discarded during compression to achieve higher compression ratios. JPEG works by dividing the image into blocks, applying a Discrete Cosine Transform (DCT) to each block, and then quantizing the DCT coefficients. Quantization involves rounding the coefficients to reduce their precision, which results in data loss. Higher compression levels lead to smaller file sizes but also more noticeable artifacts, such as blockiness and blurring. JPEG is particularly effective for photographs with smooth colour gradients.
PNG Compression: PNG (Portable Network Graphics) supports both lossless and lossy compression. Lossless compression methods, like PNG's DEFLATE algorithm, preserve all the original image data, resulting in no loss of quality. PNG is suitable for images with sharp lines, text, and graphics, where preserving detail is important. Lossy compression in PNG is less common than in JPEG, but it can be used to further reduce file size. PNG is generally preferred over JPEG for images that require transparency, as JPEG does not support transparency.
Here's a comparison of JPEG and PNG:
Feature | JPEG | PNG |
Compression Type | Lossy | Lossless & Lossy |
File Size | Smaller | Larger (lossless) |
Image Quality | Can degrade with compression | Preserves detail (lossless) |
Transparency Support | No | Yes |
Best Use | Photographs | Graphics, logos, images with text |