mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 16:56:19 +01:00
ImageProvider for raw RGBA pixels
This commit is contained in:
parent
8af5b648b5
commit
552d6d30ee
1 changed files with 41 additions and 0 deletions
41
app/lib/pixel_image_provider.dart
Normal file
41
app/lib/pixel_image_provider.dart
Normal file
|
@ -0,0 +1,41 @@
|
|||
import 'dart:typed_data';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
|
||||
/// ImageProvider for raw RGBA pixels
|
||||
class PixelImage extends ImageProvider<PixelImage> {
|
||||
PixelImage(
|
||||
this.rgba,
|
||||
this.width,
|
||||
this.height, {
|
||||
this.scale = 1.0,
|
||||
});
|
||||
|
||||
@override
|
||||
obtainKey(ImageConfiguration configuration) =>
|
||||
SynchronousFuture<PixelImage>(this);
|
||||
|
||||
@override
|
||||
load(PixelImage key, DecoderCallback decode) =>
|
||||
OneFrameImageStreamCompleter(_createImageInfo());
|
||||
|
||||
Future<ImageInfo> _createImageInfo() async {
|
||||
final codec = await ImageDescriptor.raw(
|
||||
await ImmutableBuffer.fromUint8List(rgba),
|
||||
width: width,
|
||||
height: height,
|
||||
pixelFormat: PixelFormat.rgba8888,
|
||||
).instantiateCodec();
|
||||
final frame = await codec.getNextFrame();
|
||||
return ImageInfo(image: frame.image, scale: scale);
|
||||
}
|
||||
|
||||
final Uint8List rgba;
|
||||
final int width;
|
||||
final int height;
|
||||
|
||||
/// The scale to place in the [ImageInfo] object of the image.
|
||||
final double scale;
|
||||
}
|
Loading…
Reference in a new issue