c#.net显示图像
我试图显示2个图像作为结果,但结果仅显示1个图像。我的代码有什么问题?或者我应该知道什么才能做好这项工作,或者我错过了什么?谢谢 另外,我在c#是个新手,几乎是第一次编程。因此,非常详细的解释将非常有帮助和感激。也请写答案代码来解决这个问题。谢谢 这是我的密码c#.net显示图像,c#,wpf,C#,Wpf,我试图显示2个图像作为结果,但结果仅显示1个图像。我的代码有什么问题?或者我应该知道什么才能做好这项工作,或者我错过了什么?谢谢 另外,我在c#是个新手,几乎是第一次编程。因此,非常详细的解释将非常有帮助和感激。也请写答案代码来解决这个问题。谢谢 这是我的密码 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; us
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;
using System.Threading;
namespace WpfApp1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
byte[] bitmapArray = new byte[2046 * 2046 * 3];
for (int i = 0; i < 12558348; i++)
{
bitmapArray[i] = 127;
}
PixelFormat pf = PixelFormats.Bgr24;
BitmapSource bitmap = BitmapSource.Create(2046, 2046, 96, 96, pf, null, bitmapArray, 2046 * 3);
BaslerImage.Source = bitmap;
Nothing(bitmapArray, pf);
}
async void Nothing(byte[] bitmapArray, PixelFormat pf)
{
for (int i = 0; i < 12558348; i++)
{
bitmapArray[i] = 30;
}
PixelFormat pf2 = PixelFormats.Bgr24;
BitmapSource bitmap2 = BitmapSource.Create(2046, 2046, 96, 96, pf, null, bitmapArray, 2046 * 3);
BaslerImage.Source = bitmap2;
await Task.Delay(10);
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
使用系统线程;
命名空间WpfApp1
{
///
///MainWindow.xaml的交互逻辑
///
公共部分类主窗口:窗口
{
公共主窗口()
{
初始化组件();
字节[]位图数组=新字节[2046*2046*3];
对于(int i=0;i<12558348;i++)
{
位图数组[i]=127;
}
PixelFormat pf=PixelFormats.Bgr24;
BitmapSource位图=BitmapSource.Create(2046、2046、96、96、pf、null、bitmapArray、2046*3);
BaslerImage.Source=位图;
无(位图数组,pf);
}
async void Nothing(字节[]位图数组,像素格式pf)
{
对于(int i=0;i<12558348;i++)
{
位图数组[i]=30;
}
PixelFormat pf2=PixelFormats.Bgr24;
BitmapSource bitmap2=BitmapSource.Create(2046、2046、96、96、pf、null、bitmapArray、2046*3);
BaslerImage.Source=bitmap2;
等待任务。延迟(10);
}
}
}
我相信您的任务是通过更新Image.Source属性在系列上显示多个图像。请参考下面的代码
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;
using System.Threading;
namespace WpfApp1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Nothing();
}
async void Nothing()
{
byte[] bitmapArray = new byte[2046 * 2046 * 3];
byte a = 30;
int b = 80;
var k = a * 2 + b;
for(int j =0; j < 10; j++)
{
for (int i = 0; i < 12558348; i++)
{
bitmapArray[i] = (byte)(63 + j*10);
}
PixelFormat pf = PixelFormats.Bgr24;
BitmapSource bitmap = BitmapSource.Create(2046, 2046, 96, 96, pf, null, bitmapArray, 2046 * 3);
BaslerImage.Source = bitmap;
await Task.Delay(1000);
}
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
使用系统线程;
命名空间WpfApp1
{
///
///MainWindow.xaml的交互逻辑
///
公共部分类主窗口:窗口
{
公共主窗口()
{
初始化组件();
什么都没有;
}
异步void Nothing()
{
字节[]位图数组=新字节[2046*2046*3];
字节a=30;
int b=80;
var k=a*2+b;
对于(int j=0;j<10;j++)
{
对于(int i=0;i<12558348;i++)
{
位图数组[i]=(字节)(63+j*10);
}
PixelFormat pf=PixelFormats.Bgr24;
BitmapSource位图=BitmapSource.Create(2046、2046、96、96、pf、null、bitmapArray、2046*3);
BaslerImage.Source=位图;
等待任务。延迟(1000);
}
}
}
}
您实际上想做什么?你陈述你的问题,但不是真正的任务。为什么要创建一个字节数组,然后用它来创建位图?在这两种方法中,您都会将生成的图像分配给BaslerImage.Source
…因此您会在同一位置用第二个图像覆盖第一个图像。您可能需要两个单独的位置来显示图像。我试图制作非常简单的位图图像。你能给我解释一下如何单独显示这些图像吗?我还猜测结果可能会被覆盖,但不知道如何修复。很抱歉,我的代码可能不太好看,因为我对编程非常陌生。关于如何单独显示图像
它们彼此相邻吗?上/下?还有别的吗?