If you really want
GetPixel/SetPixel
, it can only be in the cases where you need only few pixels, and then speed does not matter. If you need to copy or modify many pixels, the whole idea makes no sense. And you won't be able to do it fast anyway, no matter how hard you try. The approach is different: you need to pin a memory for a whole array of data at once and use it through pointers (unsafe code) or array indexing for massive operations. In this case, average access time per pixel can be quite small, which is all you need.
Now, you did not explain what imaging library do you want to use. Usually, you use either
System.Drawing
, which is used with
System.Windows.Forms
or just bitmaps, or, alternatively, you use WPF. It could be something else, not from Microsoft, available on all or some platforms. You should always tag such things when asking questions.
For Forms, you would need to use,
BitmapLockBits
:
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits.aspx[
^].
For WPF, you can use
System.Windows.Media.Imaging.BitmapImage
. If you need to write bitmap, you would need to use
Please see:
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapsource.aspx#inheritanceContinued[
^],
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapimage.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.aspx[
^].
You should better not mix
System.Drawing
with
WPF
, but, if it's absolutely necessary, there is an interop library:
http://msdn.microsoft.com/en-us/library/ms608869.aspx[
^].
I would not recommend to go into interop; it's much better to choose one of the alternatives.
—SA