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

Why the antialising is not applied correctly? #88

Open
EricOuellet2 opened this issue Apr 3, 2024 · 3 comments
Open

Why the antialising is not applied correctly? #88

EricOuellet2 opened this issue Apr 3, 2024 · 3 comments

Comments

@EricOuellet2
Copy link

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;
            }
        }
    }
}

@epsi1on
Copy link
Contributor

epsi1on commented Nov 6, 2024

i had same problem as in #35
I think we should first understand the code and then fix the bug our self.

@EricOuellet2
Copy link
Author

OK, thanks. It's been a while. I do not have the knowledge to fix that myself.

@epsi1on
Copy link
Contributor

epsi1on commented Nov 6, 2024

As I remember if you clear the bitmap before draw with some solid colors, with alpha = 255 (no transparency) this problem will not happen. it only happen when drawing AA line on a transparent image. Not sure, so check it yourself.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants