如何清除MFC中以前的Png图像? [英] How to clear previous Png Image in mfc?

查看:274
本文介绍了如何清除MFC中以前的Png图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

void CPictureCtrl::FreeImage()
{
FreeData();
Graphics graphics( GetDC()->GetSafeHdc() );
graphics.Clear(Color::Transparent);
// or any other color ; see Gdiplus..
}





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;
		}
	}




当我释放应清除png并显示新图像的图像时,我将得到黑色背景.但是我需要透明的背景.


我的目标是显示png,当我显示新的png时,它应该清除上一张图片.

我已经使用CStatic控件显示png.




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.

推荐答案

添加
Invalidate(true);





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);


这篇关于如何清除MFC中以前的Png图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆