Skip to content

Why the antialising is not applied correctly? #88

Description

@EricOuellet2

I wonder if I do something wrong of there is a bug.
Please look at the result obtained from simple modifications of you example: TextExample (attached image).
2024-04-03 12_03_59-WriteableBitmapEx_All (Running) - Microsoft Visual Studio

Code:

namespace WriteableBitmapEx.TextExample
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.SizeChanged += MainWindow_SizeChanged;
        }

        private void MainWindow_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (this.IsVisible)
                Draw();
        }

         WriteableBitmap bmp;

        private void Draw()
        {
            // double DIP = GetDpi(this);

            // var bmp = LoadFromFile("Assets/Overlays/19.jpg");
            var parent = UiUtility.GetVisualParent(imgMain);
            DependencyObject doParent = VisualTreeHelper.GetParent(imgMain);

            int height = (int)parent.ActualHeight;
            int width = (int)parent.ActualWidth;
            var bmp = BitmapFactory.New(width, height);

            System.Windows.Media.FormattedText formattedText;
            {
                System.Windows.FontStyle fontStyle = FontStyles.Normal;
                FontWeight fontWeight = FontWeights.Medium;

                var Text = "Now supports text!";

                var FontSize = 80;

                // var Font = new FontFamily("Sans MS");
                var Font = new FontFamily("Arial");

                // Create the formatted text based on the properties set.
                formattedText = new FormattedText(Text, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface("Arial"), FontSize, Brushes.Black); // This brush does not matter since we use the geometry of the text.                    

                // var t = new PixelsPerDip();        
            }

            bmp.DrawTextAa(formattedText, 0, 100, Colors.Black, 7);
            bmp.FillText(formattedText, 0, 100, Colors.Red);

            int[] points = { 10, 450, 60, 480, 120, 440, 180, 495, 250, 450 };
            bmp.DrawPolylineAa(points, Colors.Yellow, 7);

            imgMain.Source = bmp;
            // bmp.DrawTextAa()

        }

        public static WriteableBitmap LoadFromFile(string fileName)
        {
            using (var fileStream = File.OpenRead(fileName))
            {
                var wb = BitmapFactory.FromStream(fileStream);
                return wb;
            }
        }
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions