G->SetCompositingQuality(Gdiplus::CompositingQualityHighQuality) G->SetInterpolationMode(Gdiplus::InterpolationModeHighQuality) Gdiplus::Status stat = g->GetLastStatus() Gdiplus::Graphics * g = Gdiplus::Graphics::FromHDC(hMemDC) PatBlt(hMemDC,0,0,dwWidth,dwHeight,WHITENESS) ![]() HOldBitmap = static_cast(SelectObject(hMemDC, hBitmap)) HBitmap = ::CreateDIBSection( hdc, reinterpret_cast(&bi), Create the DIB section with an alpha channel. The following mask specification specifies a supported 32 BPP HICON CreateAlphaIcon(Gdiplus::Bitmap *pImg) I get a grayscaled alpha channel icon whichĭisplays without any artifacts. png to a PixelFormat32bppARGB bitmapĪnd then used the function below to create the icon. "stefan_full_rgba.png" which I pulled from I tested this code with the following image: Since it is your goal to produce a grayscale alpha channel iconįrom the original, this is the code that I used: Understanding something, or is it possibly a bug?. This solves my problem but it seems strange to me that directly creating aīitmap from an HICON cusses the Alpha channel to be lost. Note: my code only works for icons with an alpha channel. Now we have the icon with the alpha channel loaded into bmpAlpha! PixelFormat32bppARGB, (BYTE*)bmData.Scan0) create a new 32 bit bitmap using the bitmapDataīitmap bmpAlpha(bmData.Width, bmData.Height, bmData.Stride, Rect rectBounds(0, 0, bmpIcon.GetWidth(), bmpIcon.GetHeight() ) īmpIcon.LockBits(&rectBounds, ImageLockModeRead, create a bitmap from the ICONINFO so we can access the bitmapData The ICONINFO’s bitmap handle, get the BitmapData from it, and use theīitmapData to create another bitmap which has the alpha channel. The Solution was to Get the ICONINFO from the icon, Create a bitmap using I found the solution thanks to a link from a similar post ![]() Icon that is generated from the above function has a black outline withĪm I missing something? Any help would be greatly appreciated. The original on the toolbar and it looks perfect with smooth edges while the Positive that the original icon does in fact have alpha vales. Only has one image with a 32bit color depth and the problem persisted. ![]() To rule out other possible problems I have tried this with an icon that Icon, however the result is not an identical copy as the alpha blending has So all this function is actually doing is returning a copy of the original it is always 0 or 255 never in-between Look at the alpha layer for every pixelįor(int w = 0 w < bmpIcon.GetWidth() w++)įor(int h = 0 h < bmpIcon.GetHeight() h++) we are only using 32 bit icons with an alpha layerĪSSERT(bmpIcon.GetPixelFormat() = PixelFormat32bppARGB) ![]() The loop you will see that it is always 255 or 0. It looks at the alpha layer of every pixel, if you step through Is flattened to either opaque (255) or transparent (0) with nothing inīelow is a modified version of my function that demonstrates what is My problem is that when the bitmap is created from the icon, the alpha layer Icon handle, convert the bitmap to grayscale and then get a new Icon handle The process is easily performed with GDI+. I am trying to write a function that creates a grayscale icon based on an
0 Comments
Leave a Reply. |