Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从System.Drawing.Bitmap区域在WPF中创建图像并调整其大小_Wpf_Bitmap_Resize_Render - Fatal编程技术网

从System.Drawing.Bitmap区域在WPF中创建图像并调整其大小

从System.Drawing.Bitmap区域在WPF中创建图像并调整其大小,wpf,bitmap,resize,render,Wpf,Bitmap,Resize,Render,我正在尝试实现一个函数,该函数接受System.Drawing.Bitmap对象并将其呈现在WPF画布上。在渲染之前,必须对位图进行几次裁剪和合并 环境:运行在.NET3.5SP1上的WPF应用程序 输入:System.Drawing.Bitmap对象,尺寸为800x600,像素格式为RGB24 目标:在一行上显示由输入位图的两条条纹组成的图像。条纹是位图的两部分-0,080300和0300800600。稍后,我希望能够放大或缩小图像 我已经用GDI和Graphics.DrawImage实现了一

我正在尝试实现一个函数,该函数接受System.Drawing.Bitmap对象并将其呈现在WPF画布上。在渲染之前,必须对位图进行几次裁剪和合并

环境:运行在.NET3.5SP1上的WPF应用程序

输入:System.Drawing.Bitmap对象,尺寸为800x600,像素格式为RGB24

目标:在一行上显示由输入位图的两条条纹组成的图像。条纹是位图的两部分-0,080300和0300800600。稍后,我希望能够放大或缩小图像

我已经用GDI和Graphics.DrawImage实现了一个解决方案,它可以渲染成位图对象,但是我想提高性能,这个函数可以每秒调用30次


假设我想在WPF窗口上渲染图像,有没有更快的方法用WPF实现这一点?

到目前为止,我找到的最好的解决方案是使用WriteableBitmap,类似这样:

void Init()
{
    m_writeableBitmap = new WriteableBitmap(DesiredWidth, DesiredHeight, DesiredDpi, DesiredDpi, PixelFormats.Pbgra32, null);
{

void CopyPixels(System.Drawing.Bitmap frame, Rectangle source, Point destBegin)
{
    var bmpData = frame.LockBits(source, ImageLockMode.ReadOnly, frame.PixelFormat);
    m_writeableBitmap.Lock();

    var dest = new Int32Rect(destBegin.X, destBegin.Y, bmpData.Width, bmpData.Height);
    m_writeableBitmap.WritePixels(dest, bmpData.Scan0, bmpData.Stride * bmpData.Height, bmpData.Stride);

    m_writeableBitmap.Unlock();
    frame.UnlockBits(bmpData);
}

对于我在问题“两条条纹”中描述的用例,CopyPixels将被调用两次。

我是WPF新手,您能为我提供有用教程的链接吗?我必须主要处理位图图像创建,并在此基础上添加文本。我会为此向你道歉的