Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] The Canvas.DrawPath call leads to an incorrect result if the path points are too far from each other #3124

Open
1 task done
e1em3ntoDX opened this issue Dec 20, 2024 · 0 comments
Labels

Comments

@e1em3ntoDX
Copy link

Description

Hi,

We utilize the SkiaSharp library within one of our commercial DevExpress products to offer cross-platform drawing and printing functionalities.

Upon executing the code below, we notice a discrepancy in the resulting figure compared to the one generated using GDI+ functionality.

Although I am not sure whether this behavior is a bug, I would greatly appreciate any suggestions or recommendations on how to resolve this issue.

Code

SKPoint[] points = new SKPoint[] {
    new SKPoint(-6388600, 3162518),
    new SKPoint(-6010237, 6388600),
    new SKPoint(639, 40),
    new SKPoint(639, 40),
};
using (SKBitmap bmp = new SKBitmap(650, 350)) {
    using (SKCanvas canvas = new SKCanvas(bmp))
    using (SKPaint paint = new SKPaint())
    using (SKPath path = new SKPath()) {
        paint.Style = SKPaintStyle.Stroke;
        paint.StrokeWidth = 2;
        paint.StrokeMiter = 10;
        paint.Color = SKColors.Red;
        canvas.Clear(SKColors.White);

        path.MoveTo(points[0]);
        path.CubicTo(points[1], points[2], points[3]);
        canvas.DrawPath(path, paint);
    }
    string savePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "skia.png");
    using (FileStream stream = File.OpenWrite(savePath))
    using (SKPixmap pixmap = bmp.PeekPixels()) {
        const int compression = 5;
        SKPngEncoderOptions options = new SKPngEncoderOptions(SKPngEncoderFilterFlags.None, zLibLevel: compression);
        using (SKManagedWStream skStream = new SKManagedWStream(stream, false))
            pixmap.Encode(skStream, options);
    }
}

Expected Behavior

This is the result we obtain when we call GDI+ methods:

image

using (Image image = new Bitmap(650, 350)) {
    using (Graphics graphics = Graphics.FromImage(image)) {
        PointF[] points = new PointF[] {
            new PointF(-6388600, 3162518),
            new PointF(-6010237, 6388600),
            new PointF(639, 40),
            new PointF(639, 40),
        };
        graphics.Clear(Color.White);
        graphics.DrawBeziers(new Pen(Color.Red, 2), points);
    }
    string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "gdi+.png");
    image.Save(path, ImageFormat.Png);
}

Actual Behavior

This is the result with SkiaSharp:
image

Version of SkiaSharp

3.116.0 (Current)

Last Known Good Version of SkiaSharp

Other (Please indicate in the description)

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Windows

Platform / Operating System Version

No response

Devices

No response

Relevant Screenshots

No response

Relevant Log Output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: New
Development

No branches or pull requests

1 participant