bluefireteam / bitmap

A Flutter package for manipulating bitmaps
MIT License
176 stars 34 forks source link

How should the Uint8List for `Bitmap.fromHeadless` look #37

Closed CaptainDario closed 3 years ago

CaptainDario commented 3 years ago

First of all thank you for this package. However I am stuck while trying to convert an Uint8List to a bitmap. What I am trying is:

  final bitmap = Bitmap.fromHeadless(
    this.width,
    this.height,
    layer
  );
  final headed = bitmap.buildHeaded();
  final imgMem = Image.memory(headed);
  return imgMem;

However the code always crashes at the buildHeaded(). Now I am wondering what the problem is and how the uint8list should be build. Is it supposed to encode RGBA in separate ints like:

[255, 0, 0, 255]

for a completely red pixel?

renancaraujo commented 3 years ago

Yes, the standard for the content is RGBA32. Is the Width/Height correct for that image?

CaptainDario commented 3 years ago

Sorry, than this is my fault. From

This is useful when you are dealing with the Uint8List that ByteData generates.

I thought I can just pass the constructor the result of Picture.toByteData().asUint8List(). But now setting 4 elements for R, G, B and A does work.

Edit: Turns out that this also work with Picture.toByteData(format: ImageByteFormat.rawRgba).asUint8List()