Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8051363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:17:09+00:00 2026-06-05T07:17:09+00:00

I am working on a drawing program prototype in C#. I generate a "brush"

  • 0

I am working on a drawing program prototype in C#.

I generate a "brush" image that I blend onto a destination image, following the mouse position. It works, but blending over and over at the same place generates artifacts. In particular, transparent pixels on the brush tend to darken the destination image.

Here is the brush and the destination image with artifacts. On the right are the corresponding alpha channels. Last row shows the correct result when I use a flat brush (a semi-transparent disc).

Bug illustrated

I made a sample program illustrating the issue.

public static Bitmap GenerateBrush(double radius, Func<double, double, double> curve)
{
    int npx = (int)Math.Ceiling(radius) * 2 + 1;
    Bitmap bmp = new Bitmap(npx, npx, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
    for (int ix = 0; ix < npx; ix++) {
        for (int iy = 0; iy < npx; iy++) {
            double fx = 2.0 * ix / (double)(npx - 1) - 1.0;
            double fy = 2.0 * iy / (double)(npx - 1) - 1.0;
            double res = curve(fx, fy);
            bmp.SetPixel(ix, iy, Color.FromArgb((int)(res * 255), 255, 255, 255));
        }
    }
    return bmp;
}

static void Main(string[] args)
{
    var bmpDest = new Bitmap(200, 200, PixelFormat.Format32bppArgb);
    var graphDest = Graphics.FromImage(bmpDest);
    graphDest.Clear(Color.FromArgb(0, 255, 255, 255));

    var bmpSrc = GenerateBrush(40, delegate(double x, double y) {
        double d = Math.Max(1.0 - Math.Sqrt(x * x + y * y), 0.0);
        return 0.5 + Math.Sin((d - 0.5) * Math.PI) / 2;
    });
    
    var im = new ImageAttributes();
    im.SetColorMatrix(new ColorMatrix(
        new float[][] {
        new float[] { 1, 0, 0, 0, 0 },
        new float[] { 0, 1, 0, 0, 0 },
        new float[] { 0, 0, 0, 0, 0 },
        new float[] { 0, 0, 0, 0.3f, 0 },
        new float[] { .0f, .0f, .0f, .0f, 1 }
        }
    ));

    int nsteps = 2000;
    for (int i = 0; i < nsteps; i++) {
        var t = i / (float)nsteps;
        var xpos = 60 + (int)(Math.Sin(t*Math.PI*40) * 50);
        var ypos = 60 + (t>0.5 ? 20: -20);
        graphDest.DrawImage(bmpSrc, new Rectangle(xpos, ypos, 100, 100), 0, 0, 100, 100, GraphicsUnit.Pixel, im);
    }

    bmpDest.Save(@"test.png");
}

It seems to me like it could be due to a precision issue in the way GDI+ blends transparent images. Any thoughts?

— Edit

Same problem without color matrix (removing the last argument in DrawImage()):

enter image description here

— Edit 2

It seems like no-one has an answer for this – is the question not clear enough ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:17:10+00:00Added an answer on June 5, 2026 at 7:17 am

    Yes, truncation errors are accumulating. You might try using PixelFormat.Format32bppPArgb mode for the images, but I’m not sure it will help.

    The sure-fire cure is to accumulate the brush stroke into a single-channel image and then use that result as a mask to paint on your canvas.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on making a simple drawing program. So far I am able
I am working on kind of drawing program but I have a problem with
I am working on a project that needs rasterizing of drawings into image files.
I am working on a drawing program and am trying to figure out the
I'm working on a program for class that involves solving the Chinese Postman problem
I've been busy working on a program that can solve Minesweeper puzzles (for no
for some reason my server that uses socket.io is not working properly. The program
I am working on a web script that handles image processing using ImageMagick. It
I'm working on a simulation program that draws points and other primitives on top
I'm adding mouse rotation to my 2D drawing program. I've got all the code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.