GDI+ SRCAND for Transparency?
-
Hello Everybody, I am trying to do like this. loading a bitmap using Gdiplus and drawing that to a device context. Bitmap gbmp(bmpFile); Graphics g(dc.GetSafeHdc()); g.DrawImage(gbmp, x,y, Width, Height); this is drawing the bitmap fine. on the same device context, if i am trying to draw colors over the bitmap, then the colors are going backside of the bitmap and the bitmap is showing front. in mspaint, if i load an image, and draw colors, its spreading the colors over the bitmap. i want to do like that. is there anyway to do that? if i use BitBlt and SRCAND, then it is working fine, but i need in gdiplus. Thanks in advance, A. Gopinath.
-
Hello Everybody, I am trying to do like this. loading a bitmap using Gdiplus and drawing that to a device context. Bitmap gbmp(bmpFile); Graphics g(dc.GetSafeHdc()); g.DrawImage(gbmp, x,y, Width, Height); this is drawing the bitmap fine. on the same device context, if i am trying to draw colors over the bitmap, then the colors are going backside of the bitmap and the bitmap is showing front. in mspaint, if i load an image, and draw colors, its spreading the colors over the bitmap. i want to do like that. is there anyway to do that? if i use BitBlt and SRCAND, then it is working fine, but i need in gdiplus. Thanks in advance, A. Gopinath.
Hi tagopi, I would suggest that you have a look at the SetColorMatrix function[^] which can be used for RGBA transformations. Here is an example from one of my personal projects:
if(TRUE == m_bDisabled) { Gdiplus::ImageAttributes imageAtt; Gdiplus::ColorMatrix cm = { 0.299f, 0.299f, 0.299F, 0, 0, 0.587f, 0.587f, 0.587f, 0, 0, 0.114F, 0.114F, 0.114F, 0, 0, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; cm.m[3][3]+=0.01f; imageAtt.SetColorMatrix(&cm, Gdiplus::ColorMatrixFlagsDefault,Gdiplus::ColorAdjustTypeBitmap); gScreenBuffer.DrawImage(&memBitmap,Gdiplus::Rect(0, 0, memBitmap.GetWidth(), memBitmap.GetHeight()),0,0,memBitmap.GetWidth(),memBitmap.GetHeight(),Gdiplus::UnitPixel,&imageAtt); }
This example is used to paint my bitmap in grayscale when a button is disabled. Good Luck, -David Delaune
-
Hi tagopi, I would suggest that you have a look at the SetColorMatrix function[^] which can be used for RGBA transformations. Here is an example from one of my personal projects:
if(TRUE == m_bDisabled) { Gdiplus::ImageAttributes imageAtt; Gdiplus::ColorMatrix cm = { 0.299f, 0.299f, 0.299F, 0, 0, 0.587f, 0.587f, 0.587f, 0, 0, 0.114F, 0.114F, 0.114F, 0, 0, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; cm.m[3][3]+=0.01f; imageAtt.SetColorMatrix(&cm, Gdiplus::ColorMatrixFlagsDefault,Gdiplus::ColorAdjustTypeBitmap); gScreenBuffer.DrawImage(&memBitmap,Gdiplus::Rect(0, 0, memBitmap.GetWidth(), memBitmap.GetHeight()),0,0,memBitmap.GetWidth(),memBitmap.GetHeight(),Gdiplus::UnitPixel,&imageAtt); }
This example is used to paint my bitmap in grayscale when a button is disabled. Good Luck, -David Delaune
-
Hello David, Thanks for your reply.. This works fine for me, i changed the values as needed by me. Thanks again. A. Gopinath.