wpf 应用程序 怎样绘制一个波形,把从串口接收的数据 绘制成波形?我现在的方法的 实例化一个位图对象 在位图对象上绘制好以后 再显示。现在碰到了个问题 我不知怎样绘制在位图对象上? 求高手给点代码或给个其他的方法。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 直接贴代码,<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <Image Height="200" HorizontalAlignment="Left" Margin="24,24,0,0" Name="image1" VerticalAlignment="Top" Width="300" Loaded="image1_Loaded" /> </Grid></Window>using System;using System.Windows;using System.Windows.Media.Imaging;using System.Windows.Interop;using System.Drawing;using System.Drawing.Drawing2D;namespace WpfApplication1{ /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void image1_Loaded(object sender, RoutedEventArgs e) { Bitmap bitmap = CreateSineWave(); image1.Source = Imaging.CreateBitmapSourceFromHBitmap( bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); } private Bitmap CreateSineWave() { const int delta = 20; var bitmap = new Bitmap(300, 200); using (var g = Graphics.FromImage(bitmap)) { var path = new GraphicsPath(); for (double a = 0; a < 4 * Math.PI; a += 0.2) { double x1 = a * delta; double y1 = Math.Sin(a) * delta + 100; double x2 = (a + 0.1) * delta; double y2 = Math.Sin(a + 0.1) * delta + 100; path.AddLine((float)x1, (float)y1, (float)x2, (float)y2); } g.DrawPath(new Pen(Color.Black), path); } return bitmap; } }} ntbackup备份文件夹到指定路径命令怎么写 不能在此范围内声明名为“e”的局部变量,因为这样会使“e”具有不同的含义, 更新程序代码问题! ==反射== 有谁能给个"实用简单"的例子? c#3.0 中如何指定自定义属性的默认值? 急 急....生成word时出现"此文件正由另一程序在使用" 请问如何解决??? CArray<class,class>在C#里怎么用? 简单问题 关于调整Grid的显示格式问题 关于DataGrid的统计行和统计列的生成,请高手指点!!!!急!!!! mvc ajax.BeginForm asp.net中有没有定时器 遍历窗体 用户权限
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Image Height="200" HorizontalAlignment="Left" Margin="24,24,0,0" Name="image1" VerticalAlignment="Top" Width="300" Loaded="image1_Loaded" />
</Grid>
</Window>using System;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Interop;
using System.Drawing;
using System.Drawing.Drawing2D;namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
} private void image1_Loaded(object sender, RoutedEventArgs e)
{
Bitmap bitmap = CreateSineWave();
image1.Source = Imaging.CreateBitmapSourceFromHBitmap(
bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
} private Bitmap CreateSineWave()
{
const int delta = 20;
var bitmap = new Bitmap(300, 200);
using (var g = Graphics.FromImage(bitmap))
{
var path = new GraphicsPath();
for (double a = 0; a < 4 * Math.PI; a += 0.2)
{
double x1 = a * delta;
double y1 = Math.Sin(a) * delta + 100;
double x2 = (a + 0.1) * delta;
double y2 = Math.Sin(a + 0.1) * delta + 100; path.AddLine((float)x1, (float)y1, (float)x2, (float)y2);
}
g.DrawPath(new Pen(Color.Black), path);
} return bitmap;
}
}
}