CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2011
    Posts
    8

    Question How can i use SetBitmapBits function in C#

    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#

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: How can i use SetBitmapBits function 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

  3. #3
    Join Date
    Jun 2008
    Posts
    2,477

    Re: How can i use SetBitmapBits function 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.)

  4. #4
    Join Date
    Jan 2010
    Posts
    1,133

    Re: How can i use SetBitmapBits function in C#

    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.

  5. #5
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: How can i use SetBitmapBits function in C#

    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 if I did

  6. #6
    Join Date
    Jan 2010
    Posts
    1,133

    Re: How can i use SetBitmapBits function in C#

    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.

    Quote Originally Posted by HanneSThEGreaT
    I think I may have understood the question. [...] Sorry if I did
    But, you did: no need to feel sorry about it.

  7. #7
    Join Date
    Jul 2011
    Posts
    8

    Re: How can i use SetBitmapBits function in C#

    Please let me know the sample code of using SetBitmapBits function in c#

  8. #8
    Join Date
    Jun 2008
    Posts
    2,477

    Re: How can i use SetBitmapBits function in C#

    Quote Originally Posted by cmj View Post
    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured