.NET MAUI: Why do I get an "Invalid color" error when drawing a pattern using the GraphicsView?

Kurt K 136 Reputation points
2024-06-04T00:44:54.67+00:00

Only when drawing a pattern, I get the following error in the console:

"Invalid color: colored pattern specified with uncolored pattern color space."

The drawn pattern looks fine, despite the error.

After setting up the pattern to draw, the error appears when calling canvas.FillCircle() or canvas.FillRoundedRectangle().

The problem may be with the way I set up the pattern, but the error message does not give me enough information to go by.

Here is a simplified version of the pattern prep followed by the call to canvas.FillCircle():

            IPattern thePattern;
            PatternPaint thePaint;
		
            using (PictureCanvas picture = new PictureCanvas(0, 0, 8, 8))
            {
                picture.StrokeSize = 1;
                picture.StrokeColor = Colors.Black;
                // Hatch pattern
                picture.DrawLine(0, 8, 8, 0);
                thePattern = new PicturePattern(picture.Picture, 8, 8);
	            thePaint = new PatternPaint
                {
                    Pattern = thePattern
                };
            }
            canvas.SetFillPaint(thePaint, RectF.Zero);
            canvas.FillCircle(objRect.Center, theRadius);

I can give more details, if necessary.

Thank you.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,597 questions
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 76,551 Reputation points Microsoft Vendor
    2024-06-06T09:23:33.4033333+00:00

    Hello,

    I can get this [unknow process name]"Invalid color: colored pattern specified with uncolored pattern color space." from Application Output window.

    I find this above error only occurs in iOS platform. Android and windows platform do not have this error in output window.

    If you comment out canvas.SetFillPaint(thePaint, RectF.Zero);, then use canvas.FillCircle(objRect.Center, objRect.Width / 2); directly, this error will disappear. There are some conflicts between SetFillPaint and FillCircle.

    I check the source code about the SetFillPaint and FillCircle, I cannot find related error information.

    Please report this issue in the MAUI GitHub repo.

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.