tags:

views:

60

answers:

1
    Bitmap bmp(100,100, PixelFormat32bppARGB);
    bmp.SetPixel(2,2,Gdiplus::Color::AliceBlue);
    int x = bmp.GetHeight();
    int y = bmp.GetWidth();
    Gdiplus::Color* ccc = new Gdiplus::Color;
    Gdiplus::Color* ccc2 = new Gdiplus::Color;
    bmp.GetPixel(2,2,ccc);
    bmp.GetPixel(0,0,ccc2);

In the past sample code, the bitmap properties are always appearing as if it's null. height and width are always zero and color of any pixel is always the same. What is the right way to modify properties of the bitmap?

+2  A: 

The constructor you're calling doesn't fill in the pixel data of your bitmap. You need to call a version of bmp.FromX() after construction to fill your bitmap.

Alternately, you can call another constructor that gives you a filled bitmap.

Also, you may want to wrap your SetPixel() call with calls to LockBits() and UnlockBits().

Read up on the spec here for more details.

thebretness
Thanks for the link. I tried some functions like bmp.GetHBITMAP(Color::Azure,hBmpImage); but it still doesn't work. How can I set the width and heights for example?
Ahmad Farid
You can crop or scale the bitmap with different commands. For example you can use one of the clone functions to copy a portion of a bitmap. Read through the attached portion of the spec for more examples. Try exactly their code, then tweak some settings, use differen constructors, and such until you feel more comfortable playing around with the API.http://msdn.microsoft.com/en-us/library/ms533815%28VS.85%29.aspx
thebretness