开发者

How to modify properties of Bitmaps in C++

开发者 https://www.devze.com 2022-12-21 07:39 出处:网络
Bitmap bmp(100,100, PixelFormat32bppARGB); bmp.SetPixel(2,2,Gdiplus::Color::AliceBlue); int x = bmp.GetHeight();
    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.Get开发者_运维知识库Pixel(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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号