Click here to Skip to main content
16,010,022 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Isn't there native support for PNG in Windows? Pin
Nish Nishant27-Dec-01 23:41
sitebuilderNish Nishant27-Dec-01 23:41 
GeneralRe: Isn't there native support for PNG in Windows? Pin
markkuk27-Dec-01 23:24
markkuk27-Dec-01 23:24 
GeneralRe: Isn't there native support for PNG in Windows? Pin
Nish Nishant27-Dec-01 23:42
sitebuilderNish Nishant27-Dec-01 23:42 
GeneralRe: Isn't there native support for PNG in Windows? Pin
Christian Graus28-Dec-01 0:33
protectorChristian Graus28-Dec-01 0:33 
AnswerRe: Isn't there native support for PNG in Windows? Pin
James R. Twine28-Dec-01 7:15
James R. Twine28-Dec-01 7:15 
GeneralRe: Isn't there native support for PNG in Windows? Pin
Chris Losinger28-Dec-01 9:16
professionalChris Losinger28-Dec-01 9:16 
GeneralRe: Isn't there native support for PNG in Windows? Pin
James R. Twine28-Dec-01 16:04
James R. Twine28-Dec-01 16:04 
GeneralDisplays a Transparent Image Using Memory DC Pin
clemence27-Dec-01 21:51
clemence27-Dec-01 21:51 
Hi I would like to know if anybody can help me out here.
I want to create a transparent Image By Performing all operation on a Memory dc.
This Is what I have done so far and it works ..The only problem is that I do not know how to initialise the Bitmap which is selected into the memory DC
My current code is as folllows..

DrawTrans(CDC* pDC, COLORREF crColor)
{

COLORREF m_crWhite = RGB(255,255,255);
COLORREF m_crBlack = 0;
COLORREF crOldBack = pDC->SetBkColor(m_crWhite);
COLORREF crOldText = pDC->SetTextColor(m_crBlack);
COLORREF crOldBkMode = pDC->SetBkMode(TRANSPARENT);
// Create two memory dcs for the image and the mask
CDC dcTrans, dcImage;
CDC dcFinal;
CBitmap bmpFinal;
bmpFinal.CreateCompatibleBitmap(pDC,ImageWidth, nImageHeight);
dcFinal.CreateCompatibleDC(pDC);
dcImage.CreateCompatibleDC(pDC);
dcTrans.CreateCompatibleDC(pDC);
//m_PImageInfoData is structure contaiing
BITMAPINFO bmpInfo;
/*char* */ BYTE* pszData;
int nImageWidth = m_pImageInfoData->bmpInfo.bmiHeader.biWidth;
int nImageHeight = m_pImageInfoData->bmpInfo.bmiHeader.biHeight;
int nUsage = DIB_RGB_COLORS;
// Create the mask bitmap

CBitmap bitmapTrans, bitmapImage;
bitmapImage.CreateCompatibleBitmap(pDC, ImageWidth, nImageHeight);
bitmapTrans.CreateBitmap(nImageWidth, nImageHeight, 1, 1, NULL);
CBitmap* pOldBitmapImage = dcImage.SelectObject(&bitmapImage);
// Select the mask bitmap into the appropriate dc
CBitmap* pOldBitmapTrans = dcTrans.SelectObject(&bitmapTrans);
CBitmap *pOldBmp = dcFinal.SelectObject(&bmpFinal);
StretchDIBits(dcImage.GetSafeHdc(), 0, 0, nImageWidth, nImageHeight, 0, 0, nImageWidth, nImageHeight, m_pImageInfoData->pszData,
&(m_pImageInfoData->bmpInfo),
DIB_RGB_COLORS, SRCCOPY);

dcImage.SetBkColor(crColor);

// Build mask based on transparent colour
dcTrans.BitBlt(0, 0, nImageWidth, nImageHeight,
&dcImage,
0, 0, SRCCOPY);

dcFinal.StretchBlt(0, 0, nImageWidth, nImageHeight,
&dcImage,
0, 0,
nImageWidth, nImageHeight, SRCINVERT);
dcFinal.StretchBlt(0, 0, nImageWidth, nImageHeight,
&dcTrans,
0, 0, nImageWidth, nImageHeight,
SRCAND);
dcFinal.StretchBlt(0, 0, nImageWidth, nImageHeight,
&dcImage,
0, 0,
nImageWidth, nImageHeight,
SRCINVERT);
pDC->StretchBlt(0, 0, nImageWidth, nImageHeight,
&dcImage,
0, 0,
nImageWidth, nImageHeight,
SRCCOPY);

// Restore settings
dcTrans.SelectObject(pOldBitmapTrans);
dcImage.SelectObject(pOldBitmapImage);
dcFinal.SelectObject(pOldBmp);
bitmapTrans.DeleteObject();
bitmapImage.DeleteObject();
bmpFinal.DeleteObject();
pDC->SetBkMode(crOldBkMode);
pDC->SetTextColor(crOldText);
pDC->SetBkColor(crOldBack);
dcFinal.DeleteDC();
dcTrans.DeleteDC();
dcImage.DeleteDC();


This code works perfectly fine except for the garbage values that are displayed bcoz the Bitmap is not initialized...I would like to know what i can do to initialse the bitmap to NULL ...
Thanks ...
Frown | :(

Clemence
GeneralRe: Displays a Transparent Image Using Memory DC Pin
Mike Nordell27-Dec-01 22:58
Mike Nordell27-Dec-01 22:58 
GeneralRe: Displays a Transparent Image Using Memory DC Pin
Rickard Andersson2028-Dec-01 0:36
Rickard Andersson2028-Dec-01 0:36 
GeneralRe: Displays a Transparent Image Using Memory DC Pin
Christian Graus28-Dec-01 0:50
protectorChristian Graus28-Dec-01 0:50 
Generalinline asm problem in visual C++ Pin
HAM27-Dec-01 20:53
HAM27-Dec-01 20:53 
GeneralRe: inline asm problem in visual C++ Pin
Mike Nordell27-Dec-01 23:17
Mike Nordell27-Dec-01 23:17 
GeneralRe: inline asm problem in visual C++ Pin
HAM28-Dec-01 8:41
HAM28-Dec-01 8:41 
GeneralRe: inline asm problem in visual C++ Pin
HAM28-Dec-01 8:44
HAM28-Dec-01 8:44 
GeneralWindow being minimized Pin
Jason Hooper27-Dec-01 19:19
Jason Hooper27-Dec-01 19:19 
GeneralRe: Window being minimized Pin
Michael Dunn27-Dec-01 19:55
sitebuilderMichael Dunn27-Dec-01 19:55 
GeneralRe: Window being minimized Pin
Jason Hooper27-Dec-01 20:26
Jason Hooper27-Dec-01 20:26 
GeneralRe: Window being minimized Pin
Nish Nishant27-Dec-01 20:59
sitebuilderNish Nishant27-Dec-01 20:59 
GeneralCode Multimedia & Internet Keyboard Pin
Eugene Pustovoyt27-Dec-01 18:51
Eugene Pustovoyt27-Dec-01 18:51 
GeneralGetting the font file name Pin
v_krishnan27-Dec-01 18:51
v_krishnan27-Dec-01 18:51 
GeneralRe: Getting the font file name Pin
Mike Nordell27-Dec-01 23:25
Mike Nordell27-Dec-01 23:25 
GeneralRe: Getting the font file name Pin
v_krishnan28-Dec-01 19:14
v_krishnan28-Dec-01 19:14 
GeneralMACRO problem.... Pin
Christian Graus27-Dec-01 18:41
protectorChristian Graus27-Dec-01 18:41 
GeneralRe: MACRO problem.... Pin
PJ Arends27-Dec-01 21:29
professionalPJ Arends27-Dec-01 21:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.