C# Doubt.

  • Thread starter Thread starter vvsarun
  • Start date Start date
V

vvsarun

Hi,

i wants to use GetBitmapBits and SetBitmapBits functions with my
Bitmap object in C#.
i have imported above said functions from GDI32.dll.

GetBitmapBits is working fine and i was able to get all the bits of
the bitmap. Then i have updated the bits and called SetBitmapBits to
update the bitmap. But is not working. What might be the reason? how
can i make it work with Bitmap class?

Code.. here SetBitmapBits is not working...

Bitmap bmp =
System.Drawing.Image.FromHbitmap(hBitmap);
byte [] bitmapbits = new
byte[Form1.ActiveForm.Width*Form1.ActiveForm.Height];
int numBits = (Form1.ActiveForm.Width *
Form1.ActiveForm.Height);

int numbits = MFCLIB.GetBitmapBits(hBitmap,numBits ,
bitmapbits);
for (int intCounter = 1; intCounter <= 5000; intCounter
++)
{
byte val = bitmapbits[intCounter];
if (val == 0)
{
bitmapbits[intCounter] = 30;
}

}
uint numb = (uint)numbits;
numbits = MFCLIB.SetBitmapBits(hBitmap, numb,
bitmapbits);
MFCLIB.SelectObject((IntPtr)memDC, hBitmap);
 
Why don't you just use the Bitmap class' GetPixel and SetPixel methods
rather than resorting to PInvoke?

See also: http://www.bobpowell.net/pixel_dot.htm or the main page here:
http://www.bobpowell.net/faqmain.htm


Dave

PS - Using subjects like "C# doubt" is a sure way to keep people from
helping you. I'm in a weird mood today, so I didn't just ignore your
message like I normally would. Please just state your problem in the
subject line (e.g. Can't get SetBitmapBits to work, etc.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top