久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

用鼠標繪圖會導致像素之間出現間隙

Drawing with mouse causes gaps between pixels(用鼠標繪圖會導致像素之間出現間隙)
本文介紹了用鼠標繪圖會導致像素之間出現間隙的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

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:

解決方案

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

這篇關于用鼠標繪圖會導致像素之間出現間隙的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Right-click on a Listbox in a Silverlight 4 app(右鍵單擊 Silverlight 4 應用程序中的列表框)
WPF c# webbrowser scrolls over top menu(WPF c# webbrowser 在頂部菜單上滾動)
C# Console app - How do I make an interactive menu?(C# 控制臺應用程序 - 如何制作交互式菜單?)
How to avoid duplicate form creation in .NET Windows Forms?(如何避免在 .NET Windows Forms 中創建重復的表單?)
UI Automation Control Desktop Application and Click on Menu Strip(UI自動化控制桌面應用程序并單擊菜單條)
Removing thin border around the menuitems(刪除菜單項周圍的細邊框)
主站蜘蛛池模板: 一区二区视屏 | 国产精品视屏 | 中文字幕综合 | 日韩精品一区二区三区第95 | 国产精品二区三区 | 五月婷婷视频 | 成人黄色电影在线播放 | 男人的天堂在线视频 | 国产久| 亚洲综合在线一区 | 日本aⅴ中文字幕 | 手机在线观看av | 中文字幕在线一区 | 国产亚洲精品美女久久久久久久久久 | 黄网站免费观看 | 天天干狠狠操 | 一区二区三区四区电影视频在线观看 | 欧美日韩视频在线播放 | 免费国产视频 | 欧美黄视频 | 国产视频精品免费 | 精品久久香蕉国产线看观看亚洲 | 国产精品欧美一区二区三区不卡 | 日韩欧美专区 | 国产成人精品福利 | 日韩视频成人 | 成人三级在线播放 | 国产日韩欧美一区二区 | 四虎影院在线观看免费视频 | 黑人精品欧美一区二区蜜桃 | 中文字幕国产精品视频 | 久久婷婷国产麻豆91 | 亚洲一区视频在线 | 999国产精品视频 | 国产成人综合av | 国产高清免费视频 | 欧美日韩综合一区 | 欧美日韩不卡 | 日韩欧美在线播放 | 日韩一区二区三区在线 | 天天影视亚洲综合网 |