简体   繁体   English

在.NET中自动滚动或移动位图

[英]Auto scrolling or shifting a bitmap in .NET

I have a .NET GDI+ bitmap object (or if it makes the problem easier a WPF bitmap object) and what I want to to is shift the whole lot by dx,dy (whole pixels) and I would ideally like to do it using .NET but API calls are ok. 我有一个.NET GDI +位图对象(或者如果它使问题更容易成为WPF位图对象),我想要将dx,dy(整个像素)移位全部,并且理想情况下,我想使用。 NET,但可以调用API。 It has to be efficient bacause its going to be called 10,000 times say with moderately large bitmaps. 它必须高效,因为要使用中等大小的位图进行10,000次调用。

I have implemented a solution using DrawImage - but its slow and it halts the application for minutes while the GC cleans up the temp objects that have been used. 我已经使用DrawImage实现了一个解决方案-但它的速度很慢,并且在GC清理已使用的临时对象时会暂停应用程序几分钟。

I have also started to work on a version using ScrollDC but so far have had no luck getting it to work on the DC of the bitmap (I can make it work buy creating an API bitmap with bitmap handle, then creating a compatible DC asnd calling ScrollDC but then I have to put it back into the bitmap object). 我也已经开始使用ScrollDC进行版本开发,但是到目前为止还没有运气让它可以在位图的DC上工作(我可以通过使用位图句柄创建API位图,然后创建兼容的DC asnd调用来使其工作。 ScrollDC,但随后我必须将其放回位图对象)。

There has to be an "inplace" way of shifting a bitmap. 必须有一种“就地”移位位图的方式。 mikej 迈克

Have you found the Graphics.FromImage method? 您是否找到Graphics.FromImage方法? That will let you manipulate the bitmap directly. 这样您就可以直接操作位图。 I'm not sure what you're using with DrawImage, but Graphics.DrawImage should let you copy an area of the bitmap onto itself (and apply a shift in the process). 我不确定您在DrawImage中使用什么,但是Graphics.DrawImage应该允许您将位图的一个区域复制到自身上(并在过程中应用移位)。

Alternatively, given a Graphics object, you can use Graphics.GetHdc, ScrollDC and Graphics.ReleaseHdc. 另外,给定一个Graphics对象,可以使用Graphics.GetHdc,ScrollDC和Graphics.ReleaseHdc。

Do you just want to move the whole graphic? 您是否只想移动整个图形? DrawImage has x,y parameters to do that. DrawImage具有x,y参数来执行此操作。 I'm probably not interpreting your question correctly. 我可能无法正确解释您的问题。

As an aside, GDI is not going to be efficient period when you're working with 10,000 images. 顺便说一句,当您处理10,000张图像时,GDI不会成为有效时期。 If you want anywhere near real-time performance you're going to have to either rework your algorithm or look into a 3D API (like DirectX or OpenGL) or possibly both. 如果您希望获得接近实时性能的任何性能,则必须重新设计算法或使用3D API(例如DirectX或OpenGL)或同时使用两者。

Sorry if my question wasn't too clear. 对不起,如果我的问题不太清楚。 All I'm trying to do is in place scroll a bitmap ie do a shift operation. 我要尝试做的只是在位上滚动位图,即执行移位操作。 For example, a method like Scroll(B,1,0) would shift the entire bitmap B one pixel to the right. 例如,诸如Scroll(B,1,0)之类的方法会将整个位图B向右移动一个像素。

I've got reasonable solution using both DrawImage and the ScrollWindowEx API call which is about 10 time faster. 我有使用DrawImage和ScrollWindowEx API调用的合理解决方案,它快了大约10倍。

I'm still trying to work out how I could do something faster using WPF. 我仍在尝试找出如何使用WPF更快地执行操作的方法。

我已经在滚动位图时写出了解决问题的方法,但是我仍然不确定是否有更好的方法,如果说WPF可以做得更好?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM