在基于Dialog的应用程序中加载PNG文件 [英] load the PNG file in Dialog based application

查看:59
本文介绍了在基于Dialog的应用程序中加载PNG文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要基于示例对话框的应用程序来加载静态控件上的PNG文件。请提供在基于对话框的应用程序中加载PNG(位图)文件的代码

I need sample dialog based application to load PNG file on static control. please provide the code to load the PNG (bitmap)file in Dialog based application

推荐答案

使用向导创建基于对话框的应用程序,添加静态图片控件(样式 SS_BITMAP )到对话框模板并使用 CStatic 成员变量。



Use the wizards to create a dialog based application, add a static picture control (style SS_BITMAP) to the dialog template and use a CStatic member variable.

// CMyDialog.h 
class CMyDialog : CDialog
{
public:
    CMyDialog(CWnd* pParent = NULL);
protected:
    virtual void DoDataExchange(CDataExchange* pDX);
    void LoadPicture(LPCTSTR lpszFileName);
    CStatic m_Picture;
}

// CMyDialog.cpp
#include <atlimage.h>

void CMyDialog::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_PICT_STATIC, m_Picture);
}

void CMyDialog::LoadPicture(LPCTSTR lpszFileName)
{
    if (lpszFileName && *lpszFileName)
    {
        CImage Image;
        // Load the image as bitmap (supports PNG files)
        if (SUCCEEDED(Image.Load(lpszFileName)))
        {
            // Pass image to static picture control
            HBITMAP hOld = m_Picture.SetBitmap(Image.Detach());
            // Release old bitmap if there was one
            if (hOld)
                VERIFY(::DeleteObject(hOld));
        }
    }
}


Hey Sowmya,



将png文件添加到文件夹中的解决方案,将其命名为Images。编辑png文件的属性为:启用复制到输出目录选项。进一步为Images文件夹启用它。



然后添加以下代码或类似代码。它应该适合你。



Hey Sowmya,

Add the png file to the solution in a folder, name it as Images. Edit the properties of the png file as: Enable the Copy to Output Directory option. Further enable it for the Images folder too.

then add the below code or similar. It should work for you.

PictureBox picture = new PictureBox
        {
            Name = "pictureBox",
            Size = new Size(50, 50),
            Location = new Point(10,10),
            Visible=true
        };

        pic.ImageLocation = "..\Images\picture.jpg";
        Form1.Controls.Add(pic);





希望它有所帮助。



-anurag



hope it helps.

-anurag


参见此响应 [ ^ ]。


这篇关于在基于Dialog的应用程序中加载PNG文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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