Annotation (ink) doesn't show on the canvas with image bitmap

Hi friends,
When I am drawing on the canvas with image bitmap, the annotation (red ink) doesn't show on the screen. However, when I save the canvas, it does show the red ink.

What I expected (Expected result):

The actual result:

The weird thing is, when I save the canvas, it does show the only the ink (but not the whole image bitmap with annotation):

These are my code:

public Annotation(Stream stream)
        {
            InitializeComponent();
            undoClickCount = 0;

            using (SKImage image = SKImage.FromBitmap(SKBitmap.Decode(stream)))
            {
                SKData data = image.Encode();
                mediaFile = data.ToArray();
                saveBitmap = SKBitmap.Decode(mediaFile);
                canvasView.InvalidateSurface();
            }
        }

void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info = args.Info;
            SKSurface surface = args.Surface;
            SKCanvas canvas = surface.Canvas;
            SKCanvasView senderCanvas = (SKCanvasView)sender;

            if (!hasDrawnCanvas || senderCanvas.ClassId == "UndoPressed")
            {
                if (saveBitmap != null)
                {

                    saveBitmap = SKBitmap.Decode(mediaFile);
                    canvas.DrawBitmap(saveBitmap, info.Rect);
                }
                else
                {
                    //saveBitmap = SKBitmap.Decode(mediaFile);
                    saveBitmap = new SKBitmap(info.Width, info.Height);
                    //canvas.DrawBitmap(saveBitmap, info.Rect);
                }
                canvasView.ClassId = null;
                hasDrawnCanvas = true;
            }
        }

void UpdateBitmap()
        {
            using (saveBitmapCanvas = new SKCanvas(saveBitmap))
            {
                saveBitmapCanvas.Clear();

                foreach (SKPath path in completedPaths)
                {
                    saveBitmapCanvas.DrawPath(path, paint);
                }

                foreach (SKPath path in inProgressPaths.Values)
                {
                    saveBitmapCanvas.DrawPath(path, paint);
                }
            }
            canvasView.InvalidateSurface();
        }

Any idea/suggestion would be appreciated!
Cheers!

Answers

  • seanydaseanyda GBMember ✭✭✭✭✭

    You're showing the paint method which looks ok. The painting method is completely irrelevant to the save method. You need to draw the polylines onto the final canvas which isn't the one in the OnCanvasViewPaintSurface method.

  • ericawxwericawxw Member ✭✭

    @seanyda said:
    You're showing the paint method which looks ok. The painting method is completely irrelevant to the save method. You need to draw the polylines onto the final canvas which isn't the one in the OnCanvasViewPaintSurface method.

    After lots of debugging and testing, it finally works now! Thank you for your help.

  • MichelvanNistelrooijMichelvanNistelrooij USUniversity ✭✭

    @ericawxw said:

    After lots of debugging and testing, it finally works now! Thank you for your help.

    Possible to show the final, working code? Need this function too.
    Thanks in advance.

Sign In or Register to comment.