Since in VC++, SetBitmapBits function is there, same thing i need to use in C#.without using [DllImport("gdi32.dll")] can i perform SetBitmapBits in C#
You can always call LockBits and get a pointer to memory. You could implement your own SetBitmapBits this way and it would be pretty fast (as opposed to using the GDI+ GetPixel/SetPixel API which is slow as a dog.)
Several options: you can call LockBits(), as BigEd781 said, and then use one of the Copy() method overloads of the Marshal class, to copy the data to a managed byte array (as shown in the example here); next, i think you can mess with pointers in a so-called unsafe block, and work on the data directly; and finally, you can P/Invoke SetBitmapBits(), or better, P/Invoke SetDIBits().
Last edited by TheGreatCthulhu; July 22nd, 2011 at 07:53 PM.
Please let me know the sample code of using SetBitmapBits function in c#
Please put in a little effort, try it on your own using the advice you have been given, and then come back with a code sample if it still isn't working for you. We are not your code monkeys.
I think I may have understood the question.
I thought the OP wants to achieve the same result as SetBitmaps, but without the use of the API / P/Invoke.
Sorry, I just glanced over it, and I didn't even see the last few words...
Well, in that case - go for the either one of the first two options. I only tried the approach based on the Marshal.Copy() method, and it seems that it's generally OK; the pointer based approach should be faster.
Originally Posted by HanneSThEGreaT
I think I may have understood the question. [...] Sorry if I did
Bookmarks