2

I have a writeablebitmap.

I want to scroll the contents 1 pixel to the left, and fill in a new pixelrow in the rightmost column.

In C++ I'd memmove the entire buffer 1 pixel to the left, and overwrite the last pixel of each line - but I don't know what's the best way to do that in C# as there's no memmove.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Pygmy
  • 1,268
  • 17
  • 33

1 Answers1

-1

You can Create a new Bitmap and use DrawImage to copy a section from the source to the destination bitmap:

http://msdn.microsoft.com/en-us/library/aa457087.aspx

Then use the FillRectangle to draw a vertical rectangle one pixel wide.

Steve Wellens
  • 20,506
  • 2
  • 28
  • 69
  • That seems to be really slow. I mean, all I want to do is shift all the pixels in the buffer one place left, and add some more pixels to the right. I want to do this >60 frames per second, and I really need the processing power for other actually interesting stuff. Suppose I have 16 of those bitmaps, updating in realtime. All I need is a way to do a memmove to move pixels 1 pixelsize to the left, for the entire writeablebitmap buffer.. – Pygmy Aug 21 '11 at 00:32
  • Intellectually, a bitmap is an rectangular array of pixels. In reality, it is a single array where every nth pixel starts a new row. So there is no physical concept of shifting an image one pixel to the left. – Steve Wellens Aug 21 '11 at 02:22
  • In reality it's a 1d array which means memmoving all pixels 1-pixel-stride to the left (aka to the index of the previous pixel) results in shifting the entire image to the left, only the pixels on the rightmost column will be invalid which is not important since that's the column I intent to overwrite anyway. – Pygmy Aug 21 '11 at 16:51
  • Think of 16 people marching in a square shape, 4 girls, 4 boys, 4 girls, 4 boys. If you take the first girl on the left and remove her and let everyone else move up one spot, your first row would then be: 3 girls - 1 boy, next row: 3 boys - 1 girl, etc. You cannot 'slide' pixels around like that and expect the image to be unaltered. – Steve Wellens Aug 21 '11 at 17:05
  • The idea is not to get an unaltered image, if I'd want that I'd just leave the image alone. The idea is to use a single memmove to move the entire 1d array 1 pixel to the front. If the last column of pixels is then overwritten with new data, the image is in effect scrolling. One could also move each line individually, but the overhead of calling memmove for each line costs more cycles than just moving the entire buffer with a single call. – Pygmy Aug 21 '11 at 19:39
  • Could you post the C++ code where you use MemMove to slide a bitmap one pixel to the left? PS: You're not thinking of the BitBlt function are you (which only works on rendering devices)? – Steve Wellens Aug 21 '11 at 22:11