2

I have existing image converted to base64 and I would like to add text on top of it. However this return only the original image. Could you please advise where am I making mistake?

var signatureData = Convert.FromBase64String(signature);
            var stream = new MemoryStream(signatureData);
            var signatureBitmap = SKBitmap.Decode(stream);
            var canvas = new SKCanvas(signatureBitmap);
            var origin = new SKPoint();
            var paint = new SKPaint
            {
                TextSize = 10,
                IsAntialias = true,
                Color = SKColors.Black,
                IsStroke = false
            };
            origin.X = 10;
            origin.Y = 30;
            paint.TextAlign = SKTextAlign.Left;
            canvas.DrawText("text", origin, paint);
            canvas.Flush();
            var resultImage = SKImage.FromBitmap(signatureBitmap);
            var data = resultImage.Encode(SKEncodedImageFormat.Png, 100);
            return Convert.ToBase64String(data.ToArray());
Tes Nov
  • 83
  • 8
  • you are never converting the canvas to a bitmap after you draw on it. `resultImage` is just encoding the same `imageBytes` that you started with. See https://stackoverflow.com/questions/59392658/skiasharp-export-canvas-to-image – Jason Sep 30 '21 at 10:50
  • I have updated the question., now I am converting the bitmap but still original image – Tes Nov Sep 30 '21 at 11:37
  • no, you are still not doing anything with the canvas after you paint it. See the linked question in my last comment - it uses the Snapshot() method to capture the canvas surface – Jason Sep 30 '21 at 11:43

1 Answers1

0

This posted question actually worked for me, only the position was wrong so the text was very tiny

Tes Nov
  • 83
  • 8