0

I am facing two problems with my code:

1) I am unable to add a Base64Encoded string image as a background in Canvas. Code Code

2) Anything I am drawing in my canvas using freehand, is not clipping at the bottom edge of the canvas screenshot

Would like to have some help in achieveing the bove two tasks please. I have attached my existing code as well.

============================================================= UPDATE: So, I finally manage to add the image on canvas, thanks for the help. The issue I have landed onto is to constraint the image inside the container, regardless of the image size. I have attached screenshots of two different image sizes to better illustrate my problem :

ScreenShot 1 enter image description here

Damandroid
  • 756
  • 9
  • 31
  • Did you try to Base64 decode the string? What format is the binary image in? BMP, PNG? (Hopefully one of the supported ones.) Use `instantiateImageCodec` to convert the binary PNG into a `ui.Image` (NB that's different from the `Image` widget). Finally, use `drawImage` to draw it to the canvas. – Richard Heap Jan 01 '20 at 15:21
  • I did > var decodedImage = await instantiateImageCodec(base64Decode(image)); if (decodedImage!=null) canvas.drawImage(decodedImage,Offset(0,0),brush); I get error: Unhandled Exception: type 'Codec' is not a subtype of type 'Image' – Damandroid Jan 01 '20 at 19:00
  • Also tried: import 'dart:ui' as UI; var decodedImage = await UI.instantiateImageCodec(base64Decode(image)); But the error is the same. – Damandroid Jan 01 '20 at 19:09
  • That's because it *is* a `Codec`. `await codec.getNextFrame()` will get you a `FrameInfo` which has an `image` getter to give you the image. – Richard Heap Jan 01 '20 at 20:05
  • Could you please give some code snippet to have a better idea on what I should do, like where do I write this getNextFrame function, I am finding it a little hard to follow. I tried this: decodedImage = await (await UI.instantiateImageCodec(base64Decode(image))).getNextFrame(); but not working – Damandroid Jan 01 '20 at 21:47

0 Answers0