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

Do not work properly ImageFilter and SKMatrix [bug] #627

Closed
GalaxyVelocity opened this issue Aug 31, 2018 · 6 comments
Closed

Do not work properly ImageFilter and SKMatrix [bug] #627

GalaxyVelocity opened this issue Aug 31, 2018 · 6 comments

Comments

@GalaxyVelocity
Copy link

GalaxyVelocity commented Aug 31, 2018

Description

When adding to SKPaint filter: ImageFilter SKImageFilter.CreateDropShadow then using the transformation matrix is incomprehensible. It is expected to see that two rectangles turned and shifted to the desired values, but this does not happen. Rotates and moves only one "rectangle"(SKPath ), which is painted paintFill, the other remains untouched and in the same place.

Correct work:
If you remove "ImageFilter = SKImageFilter.CreateDropShadow...." then rotate and move both rectangles.

or

And also if you change the canvas drawing in places. Do this way:

canvas.DrawPath(testPath, paintStroke);
canvas.DrawPath(testPath, paintFill);

then everything is reflected normally. both rectangles moved.

Tell me, is this a bug or am I doing something wrong?

Code

If you run this code, you can see that one rectangle (white with shadow) turned and moved, another rectangle (with a black stroke) stayed in place at 0,0.

SKPaint paintFill = new SKPaint()
{
    Color = SKColors.White,
    Style = SKPaintStyle.Fill,
    ImageFilter = SKImageFilter.CreateDropShadow(5, 5, 15, 15, SKColors.Black, SKDropShadowImageFilterShadowMode.DrawShadowAndForeground)
};

SKPaint paintStroke = new SKPaint()
{
    Color = SKColors.Black,
    Style = SKPaintStyle.Stroke,
    StrokeWidth = 2,
};

SKPath testPath = new SKPath();
testPath.AddRect(SKRect.Create(0, 0, 300, 300));

SKMatrix matrix = canvas.TotalMatrix;
SKMatrix.PostConcat(ref matrix, SKMatrix.MakeRotationDegrees(-5f, 150, 150));
SKMatrix.PostConcat(ref matrix, SKMatrix.MakeTranslation(500, 500));
canvas.SetMatrix(matrix);

canvas.DrawPath(testPath, paintFill);
canvas.DrawPath(testPath, paintStroke);

Basic Information

.NET Framework 4.6.1
Windows Forms
SkiaSharp 1.60.3

@GalaxyVelocity GalaxyVelocity changed the title Do not work properly ImageFilter and SKMatrix Do not work properly ImageFilter and SKMatrix [bug] Sep 2, 2018
@GalaxyVelocity
Copy link
Author

Conducted several test.

Used code:

SKPaint paintFill = new SKPaint()
{
    Color = SKColors.White,
    Style = SKPaintStyle.Fill,
    ImageFilter = SKImageFilter.CreateDropShadow(5, 5, 15, 15, SKColors.Black, SKDropShadowImageFilterShadowMode.DrawShadowAndForeground)
};

SKPaint paintStroke = new SKPaint()
{
    Color = SKColors.Black,
    Style = SKPaintStyle.Stroke,
    StrokeWidth = 1
};

SKPath testPath = new SKPath();
testPath.AddRect(SKRect.Create(0, 0, 100, 100));

test 1

SKMatrix matrix = canvas.TotalMatrix;
SKMatrix.PostConcat(ref matrix, SKMatrix.MakeTranslation(200, 200));
canvas.SetMatrix(matrix);

canvas.DrawPath(testPath, paintFill);
canvas.DrawPath(testPath, paintStroke);

It's OK, the rectangle and stroke have moved to the right place.

test 2

SKMatrix matrix = canvas.TotalMatrix;
SKMatrix.PostConcat(ref matrix, SKMatrix.MakeScale(5, 5));
canvas.SetMatrix(matrix);

canvas.DrawPath(testPath, paintFill);
canvas.DrawPath(testPath, paintStroke);

It's OK, the rectangle and stroke have increased.

test 3

SKMatrix matrix = canvas.TotalMatrix;
SKMatrix.PostConcat(ref matrix, SKMatrix.MakeScale(2, 2));
SKMatrix.PostConcat(ref matrix, SKMatrix.MakeTranslation(200, 200));
canvas.SetMatrix(matrix);

canvas.DrawPath(testPath, paintFill);
canvas.DrawPath(testPath, paintStroke);

It's OK, the rectangle and stroke have increased in moved.

test 4

SKMatrix matrix = canvas.TotalMatrix;
SKMatrix.PostConcat(ref matrix, SKMatrix.MakeSkew(2, 2));
SKMatrix.PostConcat(ref matrix, SKMatrix.MakeTranslation(200, 200));
canvas.SetMatrix(matrix);

canvas.DrawPath(testPath, paintFill);
canvas.DrawPath(testPath, paintStroke);

Not everything is ok, the rectangle with the shadow with skew and moved, the stroke only increased and stayed in place, I consider this a bug.

test 5

SKMatrix matrix = canvas.TotalMatrix;
SKMatrix.PostConcat(ref matrix, SKMatrix.MakeSkew(2, 2));
canvas.SetMatrix(matrix);

canvas.DrawPath(testPath, paintFill);
canvas.DrawPath(testPath, paintStroke);

Not everything is ok, the same behavior as in test 4, only without moving.

test 6

SKMatrix matrix = canvas.TotalMatrix;
SKMatrix.PostConcat(ref matrix, SKMatrix.MakeRotationDegrees(-25f, 50, 50));
canvas.SetMatrix(matrix);

canvas.DrawPath(testPath, paintFill);
canvas.DrawPath(testPath, paintStroke);

Not everything is ok, a rectangle with a shadow in turned, the outline remained in place.

Using canvas.DrawRect the same results.

@GalaxyVelocity
Copy link
Author

If removed "ImageFilter = SKImageFilter.CreateDropShadow......" from "paintFill" all tests are normal.

@mattleibow
Copy link
Contributor

Thanks for reporting this, I will investigate further.

@GalaxyVelocity
Copy link
Author

@mattleibow Thank you for noticing this issue.

Some more simple bug tests.

test 7

  canvas.SetMatrix(SKMatrix.MakeRotationDegrees(-25f, 50, 50));

  canvas.DrawPath(testPath, paintFill);
  canvas.DrawPath(testPath, paintStroke);

Not everything is ok, a rectangle with a shadow in turned, the outline remained in place.

test 8

  canvas.SetMatrix(SKMatrix.MakeSkew(2, 2));

  canvas.DrawPath(testPath, paintFill);
  canvas.DrawPath(testPath, paintStroke);

Not everything is ok, the rectangle with the shadow increased and distorted (stretched out), the stroke has only increased, but not distorted.

Such impression that when using "ImageFilter" where that loses the transformation matrix.

@GalaxyVelocity
Copy link
Author

I tried the new version SkiaSharp 1.68.0 in Windows Forms (.NET Framework 4.6.1) All tests from previous messages passed successfully. It's OK. The bug is gone.

@mattleibow
Copy link
Contributor

That is great news! The v1.68 update had many fixes.

@ghost ghost locked as resolved and limited conversation to collaborators Aug 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants