SnapToDevicePixels=true
Das ist die Lösung. Vielen Dank.
Gruß, Noreeli
Hallo zusammen,
hier ist mein (abgespeckter) Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace OnePixLines
{
/// <summary>
/// Interaktionslogik für MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
int line_width = 4;
public MainWindow()
{
InitializeComponent();
DrawSomeLines();
}
private void DrawSomeLines()
{
canvas.Children.Clear();
for (int i = 0; i < 200; i++)
{
System.Windows.Point[] points = new System.Windows.Point[2]
{
new System.Windows.Point(line_width*i, 0),
new System.Windows.Point(line_width*i , 500)
};
points[0].X = line_width * i;
points[0].Y = 0;
points[1].X = line_width * i;
points[1].Y = 500;
DrawLine(points,i);
}
}
private void DrawLine(System.Windows.Point[] points, int color)
{
Polyline line = new Polyline();
PointCollection collection = new PointCollection();
foreach (System.Windows.Point p in points)
{
collection.Add(p);
}
line.Points = collection;
if (color % 2 == 0)
line.Stroke = new SolidColorBrush(Colors.Black);
else
line.Stroke = new SolidColorBrush(Colors.White);
line.StrokeThickness = line_width;
canvas.Children.Add(line);
}
}
}
<Window x:Class="OnePixLines.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:OnePixLines"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" Background="Transparent">
<Grid>
<Canvas x:Name="canvas" HorizontalAlignment="Left" Height="420" VerticalAlignment="Top" Width="784"/>
</Grid>
</Window>
Ich habe mir den Link zum WPF-Drawing durchgelesen. Ich verwende kein "Pen", hier ist mir nicht klar, wie ich das auf meine Verwendung von "Point" übertragen kann. Außerdem frage ich mich, wie und wo ich die Funktion "OnRender" verwenden kann/muss?
Vielen Dank für Eure Rückmeldungen.
Gruß, Noreeli
Hallo zusammen,
ich habe ein Programm geschrieben, bei dem einfarbige Balken auf einem Canvas-Element gezeichnet werden.
Nun habe ich folgendes Problem: Wenn ich bei Width "1" einstelle, sehe ich, dass die Balken nicht schwarz/weiß sind, sondern
gräuliche Farben haben (das stelle ich fest, indem ich unter Windows 10 bspw. mit der Bildschirmlupe rein zoome). Hat jemand eine Idee, woran dies liegen könnte?
Visual Studio Express 2017 für Windows Desktop, Version 15.9.17
Windows 10
Vielen Dank und Gruß,
Noreeli