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#
Printable View
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#
I don't think this is built into any of the Graphics capabilities of .NET. Guess you're stuck with API :)
Unless I'm wrong ;)
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().
I think I may have understood the question. :confused:
I thought the OP wants to achieve the same result as SetBitmaps, but without the use of the API / P/Invoke.
Sorry if I did
Sorry, I just glanced over it, and I didn't even see the last few words... :o
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.
But, you did: no need to feel sorry about it. :pQuote:
Originally Posted by HanneSThEGreaT
Please let me know the sample code of using SetBitmapBits function in c#