Scaling in Skiasharp

Yusuf 791 Reputation points
2021-02-13T04:46:12.923+00:00

Hi

I replaced this file with this code:

using SkiaSharp;  
using SkiaSharp.Views.Forms;  
using System.IO;  
using System.Reflection;  
namespace SkiaSharpFormsDemos.Curves  
{  
    public partial class BezierCurvePage : InteractivePage  
    {  
        SKBitmap resourceBitmap;  
        public BezierCurvePage()  
        {  
            string resourceID = "SkiaSharpFormsDemos.Media.Banana.jpg";  
            Assembly assembly = GetType().GetTypeInfo().Assembly;  
            using (Stream stream = assembly.GetManifestResourceStream(resourceID))  
            {  
                resourceBitmap = SKBitmap.Decode(stream);  
            }  
            touchPoints = new TouchPoint[2];  
            touchPoints[0] = new TouchPoint(50, 50);  
            touchPoints[1] = new TouchPoint(350, 350);  
            InitializeComponent();  
            baseCanvasView = canvasView;  
        }  

        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)  
        {  
            SKSurface surface = args.Surface;  
            SKCanvas canvas = surface.Canvas;  
            canvas.Clear();  
            SKRect rect = new SKRect(touchPoints[0].Center.X, touchPoints[0].Center.Y, touchPoints[1].Center.X, touchPoints[1].Center.Y);  
            // canvas.DrawBitmap(resourceBitmap, rect);   // works  
            canvas.DrawBitmap(resourceBitmap, rect, BitmapStretch.Uniform); // does not work  
            foreach (TouchPoint touchPoint in touchPoints)  
            {  
                touchPoint.Paint(canvas);  
            }  
        }  
    }  
}  

When using BitmapStretch.Uniform bitmap angles are drawn away from touch points. (line 31).

67721-67643-screenshot-1-1.png

How to make bitmap in the correct positions for touch points?
Thanks

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

Answer accepted by question author
  1. Cole Xia (Shanghai Wicresoft Co,.Ltd.) 6,756 Reputation points
    2021-02-15T06:49:32.747+00:00

    Hello,

    Welcome to Microsoft Q&A!

    The behavior is normal , the ratio of that image keeps the same if we select Uniform .

    The scale is decided by the min ratio value of the with and height .

    68046-capture.png

    If the height ratio is greater than width ratio

    68056-captu2re.png

    If the width ratio is greater than height ratio

    68008-captu444re.png


    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.


1 additional answer

Sort by: Most helpful
  1. Yusuf 791 Reputation points
    2021-02-14T14:37:10.387+00:00

    Any idea to solve this issue?

    0 comments No comments

Your answer

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