Skip to content

Bug using toByteData on a PictureRecorder generated image #23621

@DavBfr

Description

@DavBfr

Using the Flutter master branch, this code fails to render the image:

    final recorder = ui.PictureRecorder();
    final canvas = ui.Canvas(recorder, Rect.fromLTWH(0.0, 0.0, 100.0, 100.0));
    final paint = ui.Paint()..color = Colors.red;
    final data = base64.decode('R0lGODdhZABkAIACAAZ/fwzAwCwAAAAAZABkAAACroyPqcvtD6OctNqLs968+w+G4kiW5omm6sq27gvH8kzX9o3n+s73/g8MCofE4g6ATCqXzKbzCY1Kp9Sq9YrNarfcrvcLDovH5LL5jE6r1+y2+w2Py+f0uv2Oz+v3/L7/DxgoOEhYaHiImKi4yNjo+AgZKTlJWWl5iZmpucnZ6fkJGio6SlpqeoqaqrrK2ur6CjtmNEtba3uLm6u7y9vr+wscLDxMXGx8jJysvPxTAAA7');
    final codec = await ui.instantiateImageCodec(data);
    final frame = await codec.getNextFrame();
    canvas.drawImage(frame.image, ui.Offset.zero, paint);
    canvas.drawLine(Offset.zero, Offset(100.0, 100.0), paint);
    final picture = recorder.endRecording();
    final image = picture.toImage(100, 100);
    final imageBytes = await image.toByteData(format:ui.ImageByteFormat.png);

the resulting png only contains the line, but not the bitmap image (base64).
using flutter run --enable-software-rendering the bitmap image is rendered correctly.

This bug is not present using the Flutter tag v0.5.7, after that it stopped working.
It is related to #17687, and #21618

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: API breakBackwards-incompatible API changesengineflutter/engine related. See also e: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions