How to fill color inside dots?

Shashank Sivakoti 1 Reputation point
2022-11-09T18:24:03.9+00:00

258770-console2.png

Hi Team,

To to fill the Orange color inside dots, I am using this namespace Microsoft.Maui.Graphics

----------

using System;  
   
using System.IO;  
// These packages are available on NuGet  
using Microsoft.Maui.Graphics;  
using Microsoft.Maui.Graphics.Skia;  
  
namespace ConsoleApp1  
{  
    internal class Program  
    {  
        static void Main(string[] args)  
        {   
            // Create a bitmap in memory and draw on its Canvas  
            SkiaBitmapExportContext bmp = new(1000, 1000, 1.0f);  
            ICanvas canvas = bmp.Canvas;  
  
            // Draw a big blue rectangle with a dark border  
            Rect backgroundRectangle = new(0, 0, bmp.Width, bmp.Height);  
            //canvas.FillColor = Color.FromArgb("#e39e00");  
            canvas.FillRectangle(backgroundRectangle);  
            canvas.StrokeColor = Colors.Black;  
            canvas.StrokeSize = 1;  
            canvas.DrawRectangle(backgroundRectangle);  
               
  
            IPattern pattern;  
            SolidPaint solidPaint = new SolidPaint(Colors.Red);  
            // Create a 10x10 template for the pattern  
            using (PictureCanvas picture = new PictureCanvas(0, 0, 100, 100))  
            {  
              picture.StrokeColor = Colors.Orange;  
                picture.FontColor = Color.FromRgba("#e39e00");  
                picture.DrawCircle(50, 50, 25);   
                picture.DisplayScale = 1;  
                picture.FillColor = Colors.Red;                  
                pattern = new PicturePattern(picture.Picture, 10, 10);  
                   
            }  
  
            // Fill the rectangle with the 10x10 pattern  
            PatternPaint patternPaint = new PatternPaint  
            {  
                Pattern = pattern,ForegroundColor= Colors.Red,  
            };  
             
            canvas.SetFillPaint(patternPaint, RectF.Zero);  
               
            canvas.FillRectangle(backgroundRectangle);  
               
            // Save the image as a PNG file  
            bmp.WriteToFile("console2.png");  
        }  
}  
}  
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,927 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 36,231 Reputation points Microsoft Vendor
    2022-11-10T02:59:17.31+00:00

    Hello,

    You need to modify picture.DrawCircle(50, 50, 25); to picture.FillCircle(50, 50, 25); to fill color.

    Please refer to Draw graphical objects to get more details.

    Best Regards,

    Alec Liu.


    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.