This directory contains comprehensive examples demonstrating the usage of the Navigine SDK's BitmapRegionDecoder across all supported platforms.
Overview
The BitmapRegionDecoder is responsible for decoding bitmap images from byte arrays and extracting specific regions. It provides functionality for:
- Image Decoding: Creating decoders from raw image data (PNG, JPG, SVG)
- Region Extraction: Decoding specific rectangular regions from images
- Sample Size Control: Optimizing memory usage with subsampling
- Performance Optimization: Efficient handling of large images
Key Components
BitmapRegionDecoder
The main class for bitmap region decoding operations:
newInstance()
- Create decoder from byte array data
decodeRegion()
- Decode specific rectangular region with sample size control
Rectangle
Represents a rectangular region for image decoding:
x
, y
- Origin coordinates
width
, height
- Rectangle dimensions
Platform-Specific Files
Dart/Flutter
Java
Kotlin
Objective-C
Swift
Key Documentation Tags
BitmapRegionDecoder Methods
[platform_BitmapRegionDecoder_newInstance]
- Creating decoder instances
[platform_BitmapRegionDecoder_decodeRegion]
- Decoding image regions
[platform_BitmapRegionDecoder_decodeRegion_sampleSize]
- Decoding with sample size control
[platform_BitmapRegionDecoder_decodeRegion_multiple]
- Decoding multiple regions
Rectangle Properties
[platform_Rectangle_constructor]
- Creating rectangles
[platform_Rectangle_getX]
- Getting X coordinate
[platform_Rectangle_getY]
- Getting Y coordinate
[platform_Rectangle_getWidth]
- Getting width
[platform_Rectangle_getHeight]
- Getting height
Common Usage Patterns
1. Creating a Decoder
Uint8List imageData = loadImageData();
BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(imageData);
2. Defining Regions
Rectangle region = Rectangle(100, 100, 400, 300);
int x = region.x;
int y = region.y;
int width = region.width;
int height = region.height;
3. Decoding Regions
ImageWrapper image = decoder.decodeRegion(region, 1);
ImageWrapper thumbnail = decoder.decodeRegion(region, 4);
4. Multiple Region Decoding
List<Rectangle> regions = [
Rectangle(0, 0, 256, 256),
Rectangle(256, 0, 256, 256),
Rectangle(0, 256, 256, 256),
Rectangle(256, 256, 256, 256),
];
for (Rectangle region in regions) {
ImageWrapper image = decoder.decodeRegion(region, 1);
public processImage(image);
}
5. Performance Optimization
Rectangle largeRegion = Rectangle(0, 0, 1024, 768);
List<int> sampleSizes = [1, 2, 4, 8, 16];
for (int sampleSize in sampleSizes) {
final stopwatch = Stopwatch()..start();
ImageWrapper image = decoder.decodeRegion(largeRegion, sampleSize);
stopwatch.stop();
print("Sample size $sampleSize: ${stopwatch.elapsedMilliseconds}ms");
}
6. Error Handling
try {
BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(invalidData);
ImageWrapper image = decoder.decodeRegion(region, 1);
} catch (e) {
print("Failed to decode image: $e");
}
Running Examples
Dart/Flutter
cd examples/BitmapRegionDecoder/dart
dart bitmap_region_decoder_example.dart
Java
cd examples/BitmapRegionDecoder/java
javac BitmapRegionDecoderExample.java
java BitmapRegionDecoderExample
Kotlin
cd examples/BitmapRegionDecoder/kotlin
kotlinc BitmapRegionDecoderExample.kt -include-runtime -d BitmapRegionDecoderExample.jar
java -jar BitmapRegionDecoderExample.jar
Objective-C
cd examples/BitmapRegionDecoder/objc
clang -framework Foundation BitmapRegionDecoderExample.m -o BitmapRegionDecoderExample
./BitmapRegionDecoderExample
Swift
cd examples/BitmapRegionDecoder/swift
swift BitmapRegionDecoderExample.swift
Advanced Features
Sample Size Optimization
The sample size parameter controls subsampling for memory optimization:
ImageWrapper fullRes = decoder.decodeRegion(region, 1);
ImageWrapper halfRes = decoder.decodeRegion(region, 2);
ImageWrapper quarterRes = decoder.decodeRegion(region, 4);
Rectangle Manipulation
Create different rectangle variations for various use cases:
Rectangle base = Rectangle(100, 100, 200, 150);
Rectangle halfWidth = Rectangle(base.x, base.y, base.width / 2, base.height);
Rectangle halfHeight = Rectangle(base.x, base.y, base.width, base.height / 2);
Rectangle centered = Rectangle(base.x + 50, base.y + 25, base.width - 100, base.height - 50);
Multiple Image Formats
The decoder supports various image formats:
Uint8List pngData = loadPngData();
BitmapRegionDecoder pngDecoder = BitmapRegionDecoder.newInstance(pngData);
Uint8List jpegData = loadJpegData();
BitmapRegionDecoder jpegDecoder = BitmapRegionDecoder.newInstance(jpegData);
Uint8List svgData = loadSvgData();
BitmapRegionDecoder svgDecoder = BitmapRegionDecoder.newInstance(svgData);
Performance Considerations
Memory Usage
- Use appropriate sample sizes for large images
- Decode only the regions you need
- Consider the trade-off between quality and memory usage
Processing Speed
- Larger sample sizes decode faster but with lower quality
- Multiple small regions may be faster than one large region
- Profile your specific use case for optimal performance
Error Handling
- Always validate image data before creating decoders
- Handle invalid rectangle coordinates gracefully
- Implement fallback strategies for failed decodings
Notes
- All examples demonstrate the same functionality across platforms
- Image data is typically loaded from files or network sources
- Sample size must be a positive integer (1 = full resolution)
- Rectangle coordinates are zero-based
- The decoder supports PNG, JPG, and SVG formats
- Decoded images are returned as ImageWrapper objects
- Performance varies significantly with image size and sample size
- Memory usage scales with decoded image dimensions
- Error handling is important for robust applications