首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >wpf 2d高性能显卡

wpf 2d高性能显卡
EN

Stack Overflow用户
提问于 2009-09-28 15:54:04
回答 2查看 4K关注 0票数 7

基本上,我想在WPF中使用GDI类型的功能,在那里我可以将像素写入位图,并通过WPF更新和显示该位图。注意,我需要能够在飞行中通过更新像素来响应鼠标移动的位图动画。我读到过InteropBitmap非常适合这样做,因为您可以写入内存中的像素,并将内存位置复制到位图中--但我没有任何好的示例可供参考。

有没有人知道有什么好的资源、教程或博客,可以使用InteropBitmap或其他一些类在WPF中制作高性能的2D图形?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-10-01 16:20:46

这是我发现的:

我创建了一个子类化Image的类。

代码语言:javascript
运行
复制
public class MyImage : Image {
    // the pixel format for the image.  This one is blue-green-red-alpha 32bit format
    private static PixelFormat PIXEL_FORMAT = PixelFormats.Bgra32;
    // the bitmap used as a pixel source for the image
    WriteableBitmap bitmap;
    // the clipping bounds of the bitmap
    Int32Rect bitmapRect;
    // the pixel array.  unsigned ints are 32 bits
    uint[] pixels;
    // the width of the bitmap.  sort of.
    int stride;

public MyImage(int width, int height) {
    // set the image width
    this.Width = width;
    // set the image height
    this.Height = height;
    // define the clipping bounds
    bitmapRect = new Int32Rect(0, 0, width, height);
    // define the WriteableBitmap
    bitmap = new WriteableBitmap(width, height, 96, 96, PIXEL_FORMAT, null);
    // define the stride
    stride = (width * PIXEL_FORMAT.BitsPerPixel + 7) / 8;
    // allocate our pixel array
    pixels = new uint[width * height];
    // set the image source to be the bitmap
    this.Source = bitmap;
}

WriteableBitmap有一个名为WritePixels的方法,它接受一个无符号整数数组作为像素数据。我将图像的源设置为WriteableBitmap。现在,当我更新像素数据并调用WritePixels时,它会更新图像。

我将业务点数据作为点列表存储在一个单独的对象中。我对列表执行转换,并用转换后的点更新像素数据。这样就不会产生来自Geometry对象的开销。

仅供参考,我将点与使用Bresenham算法绘制的线连接起来。

这种方法非常快。我更新了大约50,000个点(和连接线)来响应鼠标的移动,没有明显的延迟。

票数 5
EN

Stack Overflow用户

发布于 2009-09-28 16:01:53

这里有一篇关于使用Web cameras with InteropBitmap的博客文章。它包括一个完整的源代码项目,演示InteropBitmap的用法。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1487831

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档