views:

395

answers:

4

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. It has to be efficient bacause its going to be called 10,000 times say with moderately large bitmaps.

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.

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).

There has to be an "inplace" way of shifting a bitmap. mikej

A: 

Have you found the Graphics.FromImage method? 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).

Alternatively, given a Graphics object, you can use Graphics.GetHdc, ScrollDC and Graphics.ReleaseHdc.

Tim Robinson
A: 

Do you just want to move the whole graphic? DrawImage has x,y parameters to do that. 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. 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.

Ron Warholic
A: 

Sorry if my question wasn't too clear. All I'm trying to do is in place scroll a bitmap i.e. do a shift operation. For example, a method like Scroll(B,1,0) would shift the entire bitmap B one pixel to the right.

I've got reasonable solution using both DrawImage and the ScrollWindowEx API call which is about 10 time faster.

I'm still trying to work out how I could do something faster using WPF.

mikej
A: 

I've written up my solution to the problem at Scrolling a bitmap but I'm still not sure that there isn't a better way and if it might be better done in say WPF?

mikej