Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
C++
void CPictureCtrl::FreeImage()
{
FreeData();
Graphics graphics( GetDC()->GetSafeHdc() );
graphics.Clear(Color::Transparent);
// or any other color ; see Gdiplus..
}


C++
m_picCtrl.FreeImage();
	CFile picFile;
	if(picFile.Open(_T("acoustic grand piano_small.png"), CFile::modeReadWrite | CFile::typeBinary))
	{
		cout("opened");
		BYTE* pBuffer = new BYTE[(unsigned int)picFile.GetLength()];
		if(pBuffer != NULL)
		{
			picFile.Read(pBuffer, (UINT)picFile.GetLength());

			//Load the Image
			cout("displayed");
				m_picCtrl.Load(pBuffer, (size_t)picFile.GetLength());

			delete pBuffer;
		}
	}



When I freeImage which should clear the png and display new i am getting black background. But I need transparent background.


My objective is display png and when I display new png it should clear the previous pic.

I have used CStatic control to display the png.
Posted
Updated 3-May-12 18:55pm
v2

1 solution

Add
C++
Invalidate(true);


C++
m_picCtrl.FreeImage();
    CFile picFile;
    if(picFile.Open(_T("acoustic grand piano_small.png"), CFile::modeReadWrite | CFile::typeBinary))
    {
        cout("opened");
        BYTE* pBuffer = new BYTE[(unsigned int)picFile.GetLength()];
        if(pBuffer != NULL)
        {
            picFile.Read(pBuffer, (UINT)picFile.GetLength());

            //Load the Image
            cout("displayed");
                m_picCtrl.Load(pBuffer, (size_t)picFile.GetLength());

            delete pBuffer;
        }
    }
Invalidate(true);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900