Save the Image with Position Marker Xamarin.Forms C#

Akshay Dixit 21 Reputation points
2021-01-25T09:31:45.943+00:00

Image Marker

As per the Image Yellow Marker marks the part of the Vehicle.
As I am successfully marking this Image using Xamarin.Forms. Now the problem is that my Image is using the marker easily but the issue lies in that I cannot save the whole Image with the Marker.

I am using SkiaSharp & TouchTracking.Forms to get the coordinate of clicks on an Image. Then I am placing the marker on that position.

Here is the code behind this - <br>

In XAML file

<AbsoluteLayout x:Name="myabs1" HeightRequest="400" >
                                <Image Source="logo.png" Aspect="AspectFill" AbsoluteLayout.LayoutBounds="0,0,1,1"
                                AbsoluteLayout.LayoutFlags="SizeProportional"/>
                                <forms:SKCanvasView
                                AbsoluteLayout.LayoutBounds="0,0,1,1"
                                AbsoluteLayout.LayoutFlags="SizeProportional">
                                    <forms:SKCanvasView.Effects>
                                        <tt:TouchEffect Capture="True"  TouchAction="TouchEffect_TouchAction1" />
                                    </forms:SKCanvasView.Effects>
                                </forms:SKCanvasView>
                            </AbsoluteLayout>

In Xaml.cs

xPos = args.Location.X;
                var y = args.Location.Y;
                var v = new PinOption();
                AbsoluteLayout.SetLayoutBounds(v, new Rectangle(xPos, y, 0.25, 0.25));
                AbsoluteLayout.SetLayoutFlags(v, AbsoluteLayoutFlags.SizeProportional);
                myabs1.Children.Add(v);

PinOption is the view in which the Image & it's further Functionality is written.<br>

Please suggest saving the whole image with the Marker.

Developer technologies | .NET | Xamarin
Developer technologies | C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,971 Reputation points
    2021-01-25T13:18:30.917+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    For this function, try the two ways:

    1.You could take a screenshot with the frame of the Image using Xamarin.Essentials.Screenshot and save the screenshot.

    2.Or try get the sKBitmap from the Image using SKBitmap.Decode method. After drawing on the skBitmap, save the bitmap to file using SKImage.Encode method.

       var _bitmap = SKBitmap.Decode(imageStream);//or path  
       SKImage image = SKImage.FromBitmap(_bitmap);  
    
       SKData data = image.Encode();  
       //save the image using the data  
    

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.