heic2png 0.0.2
heic2png: ^0.0.2 copied to clipboard
A Flutter plugin that converts HEIC/HEIF images to PNG using native platform APIs (iOS, Android, macOS, Windows, Linux).
heic2png
A Flutter plugin that converts HEIC/HEIF images to PNG using native platform APIs. Fully offline, no third-party services -- just lossless conversion on-device.
Features #
- Lossless HEIC/HEIF to PNG conversion
- Convert to file or to in-memory bytes
- Configurable PNG compression level (0-9)
- Metadata preservation (ICC color profiles, EXIF data)
- Cross-platform: iOS, Android, macOS, Windows, Linux
- Uses native APIs on each platform for maximum performance:
- iOS / macOS: CoreGraphics / ImageIO
- Android: BitmapFactory + ExifInterface
- Windows: Windows Imaging Component (WIC)
- Linux: libheif + libpng
Installation #
dependencies:
heic2png: ^0.0.1
iOS #
No additional setup needed (iOS 12.0+).
Android #
Requires Android 9 (API 28) or later (native HEIF decoder support).
Set minSdk = 28 in your app's android/app/build.gradle.kts:
android {
defaultConfig {
minSdk = 28
}
}
macOS #
No additional setup needed (macOS 10.13+).
Windows #
Requires Windows 10 version 1809 or later. The HEIF Image Extensions from the Microsoft Store may be required on Windows 10; Windows 11 bundles the codec.
Linux #
Install the required native libraries:
sudo apt install libheif-dev libpng-dev
Usage #
Convert to a file #
import 'package:heic2png/heic2png.dart';
final success = await Heic2png.convert('/path/to/input.heic', '/path/to/output.png');
if (success) {
print('Converted successfully!');
}
Convert to bytes #
final bytes = await Heic2png.convertToBytes('/path/to/input.heic');
if (bytes != null) {
// Use the PNG bytes (e.g. display with Image.memory)
}
Compression level #
Control how much effort is spent compressing the output PNG. 0 is fastest (largest file), 9 is slowest (smallest file). Default is 6.
// Fastest conversion, larger file
await Heic2png.convert(input, output, compressionLevel: 0);
// Maximum compression, slower
await Heic2png.convert(input, output, compressionLevel: 9);
// Also works with convertToBytes
final bytes = await Heic2png.convertToBytes(input, compressionLevel: 9);
Metadata preservation #
By default, ICC color profiles and EXIF data (camera info, GPS, orientation, date/time) are preserved from the source HEIC file. Set preserveMetadata: false to strip all metadata:
// Strip all metadata (ICC profile, EXIF, GPS, etc.)
await Heic2png.convert(input, output, preserveMetadata: false);
// Combine options
final bytes = await Heic2png.convertToBytes(
input,
compressionLevel: 0,
preserveMetadata: false,
);
API #
| Method | Description |
|---|---|
Heic2png.convert(inputPath, outputPath, {compressionLevel, preserveMetadata}) |
Converts a HEIC file to PNG and writes it to outputPath. Returns true on success. |
Heic2png.convertToBytes(inputPath, {compressionLevel, preserveMetadata}) |
Converts a HEIC file to PNG and returns the bytes as Uint8List. Returns null on failure. |
Parameters #
| Parameter | Type | Default | Description |
|---|---|---|---|
inputPath |
String |
required | Path to the source HEIC/HEIF file. |
outputPath |
String |
required | Path for the output PNG file (convert only). |
compressionLevel |
int |
6 |
PNG compression effort, 0 (fastest) to 9 (smallest). |
preserveMetadata |
bool |
true |
Preserve ICC color profiles and EXIF data from the source. |
Platform notes #
Compression level #
| Platform | Behavior |
|---|---|
| Linux | Maps directly to zlib compression level (0-9). Full granularity. |
| iOS / macOS | Controls PNG row filter strategy: 0 = no filter (fastest), 1-9 = adaptive filter (best compression). Levels 1-9 produce the same output. |
| Windows | Same as iOS/macOS (WIC FilterOption). |
| Android | Accepted but has no effect. Android's Bitmap.compress(PNG) uses a fixed internal compression level. |
Metadata preservation #
| Metadata | iOS | Android | macOS | Windows | Linux |
|---|---|---|---|---|---|
| ICC color profiles | Yes | No | Yes | Yes | Yes |
| EXIF data | Yes | Yes | Yes | No | Yes (libpng >= 1.6.32) |
- iOS / macOS preserve all metadata (EXIF, ICC, GPS, TIFF tags, XMP) automatically via
CGImageDestinationAddImageFromSource. - Android transfers EXIF tags (camera info, GPS, orientation, date/time) via AndroidX
ExifInterface. ICC color profile transfer is not supported -- colors are converted to sRGB during encoding. - Windows preserves ICC color profiles via WIC color contexts. EXIF transfer across container formats is not supported.
- Linux preserves ICC profiles via
png_set_iCCPand EXIF viapng_set_eXIf_1(requires libpng 1.6.32+). On older libpng versions, EXIF is silently skipped.
Example #
See the example app for a complete working demo.
License #
MIT -- see LICENSE for details.