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 7081593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:56:24+00:00 2026-05-28T06:56:24+00:00

I have been creating a drawing app as a test for WPF, and have

  • 0

I have been creating a drawing app as a test for WPF, and have been going well. The problem I’ve run into is that if I draw the pixel under the mouse to a bitmap each time it moves, I only get one pixel per update. When the mouse moves around fast it doesn’t draw the pixels in between. I need to know what the best way to draw a line between to pixels is in WPF using WriteableBitmap

EDIT: Now I have this:

LinesNotConnected

  • 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-05-28T06:56:25+00:00Added an answer on May 28, 2026 at 6:56 am

    If you want to draw a line, you shouldn’t just change colors of one pixel at a time, but rather save position of the mouse in each MouseMove event handling method.

    Then, you should draw a line between previous position (the one saved from the previous event occurrence) and draw a Line between those two points. This will make the line to be continuous. Information about drawing lines on WriteableBitmap can be found here: Drawing line using WPF WriteableBitmap.BackBuffer.

    After drawing the line, don’t forget to update the previous position saved to the current one :).

    UPDATE

    I’ve also found another solution.

    Define XAML with Image you want to draw on:

    <Window x:Class="SampleWPFApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="500" Width="520" Loaded="Window_Loaded" PreviewMouseDown="Window_PreviewMouseDown">
    <Grid x:Name="layoutRoot" Background="Transparent">
        <Image x:Name="image" />
    </Grid>
    

    And then, add code behind with the events handled:

    //set width and height of your choice
    RenderTargetBitmap bmp = null;
    //...
    private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //initialize RenderTargetBitmap object
            bmp = new RenderTargetBitmap((int)this.ActualWidth, (int)this.ActualHeight, 90, 90, PixelFormats.Default);
    
            //set initialized bmp as image's source
            image.Source = bmp;
        }
    
        /// <summary>
        /// Helper method drawing a line.
        /// </summary>
        /// <param name="p1">Start point of the line to draw.</param>
        /// <param name="p2">End point of the line to draw.</param>
        /// <param name="pen">Pen to use to draw the line.</param>
        /// <param name="thickness">Thickness of the line to draw.</param>
        private void DrawLine(Point p1, Point p2, Pen pen, double thickness)
        {
            DrawingVisual drawingVisual = new DrawingVisual();
    
            using (DrawingContext drawingContext = drawingVisual.RenderOpen())
            {
                //set properties of the Pen object to make the line more smooth
                pen.Thickness = thickness;
                pen.StartLineCap = PenLineCap.Round;
                pen.EndLineCap = PenLineCap.Round;
    
                //write your drawing code here
                drawingContext.DrawLine(pen, p1, p2);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been creating Unit tests like crazy and find that I'm often having
I have been creating a peer to peer connection for a new game, that
I have been tasked with creating a program that will generate an amortization schedule.
I have been reading that creating dependencies by using static classes/singletons in code, is
Since I created my repository it appears that the tags I have been creating
I have been creating object for a project and there are some instances that
I have been creating a web app and am looking to expand. In my
I have been creating a php application that makes quite a few queries to
The Background: I have been creating a script that based on input csv's that
I'm new to using Simulink, and have been creating some models/libraries that have roughly

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.