最近在做界面
老大说要显示PNG 的图片
但是win32的GDI只能导入bmp图片
在网上搜了一下下,可以用GDI+的样子
但是编译还是通不过
以下注意事项也注意过了
1、使用GDI+时声明一下
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment(lib, "gdiplus")
2、再下载最新的SDK,将在VC环境中添加最新SDK的Include&Lib
3、上面两条都不是我最想说的WIN32 DLL中使用GDI+需要注意的。如果仅这样在编译时是通不过。将stdafx.h中向导生成的WIN32_LEAN_AND_MEAN宏注释掉就可以了。

但是还是提示什么namespace那边有问题难道win32不认得namespace??那我该怎么做才能显示png的图片呢
高手救救命啊

小妹分不多,回答的好的话,愿意把分全给你哦

解决方案 »

  1.   

    你新建立一个工程,专门load png图片,看看是否问题依旧?
    如果正常说明,还是“你的工程”的问题。
      

  2.   

    VC2005直接可以用GDI+,无需安装新的SDK
      

  3.   

    下载一个PNG开源库,BUILD一个LIB,直接用多方便啊!
      

  4.   

    对哦,忘记给出错误信息了,如下
    c:\gdi+\includes\gdiplus.h(105) : error C2061: syntax error : identifier 'Gdiplus'
    c:\gdi+\includes\gdiplus.h(105) : error C2059: syntax error : ';'
    c:\gdi+\includes\gdiplus.h(106) : error C2449: found '{' at file scope (missing function header?)
    c:\gdi+\includes\gdiplus.h(152) : error C2059: syntax error : '}'双击错误定位到了
    namespace Gdiplus
    {
        namespace DllExports
        {
            #include "GdiplusMem.h"
        };    #include "GdiplusBase.h"    // The following headers are used internally as well
        #include "GdiplusEnums.h"
        #include "GdiplusTypes.h"
        #include "GdiplusInit.h"
        #include "GdiplusPixelFormats.h"
        #include "GdiplusColor.h"
        #include "GdiplusMetaHeader.h"
        #include "GdiplusImaging.h"

    的namespace前面是不是win32不支持NAMESPACE呢??
      

  5.   

    http://blog.chinaunix.net/u/25199/showart.php?id=254199
      

  6.   

    lib文件comment了没?GDI+的startup涵数调了没?
      

  7.   

    按楼上的说法做了,还是这样的错误555
    windraw.c
    c:\program files\microsoft visual studio\vc98\include\gdiplus.h(105) : error C2061: syntax error : identifier 'Gdiplus'
    c:\program files\microsoft visual studio\vc98\include\gdiplus.h(105) : error C2059: syntax error : ';'
    c:\program files\microsoft visual studio\vc98\include\gdiplus.h(106) : error C2449: found '{' at file scope (missing function header?)
    c:\program files\microsoft visual studio\vc98\include\gdiplus.h(152) : error C2059: syntax error : '}'
      

  8.   

    看看我的博客吧,里面有在vc6下使用gdi+的详细步骤,以及应该注意的问题。
      

  9.   

    namespace Gdiplus
    {
        namespace DllExports
        {
            #include "GdiplusMem.h"
        };    #include "GdiplusBase.h"    // The following headers are used internally as well
        #include "GdiplusEnums.h"
        #include "GdiplusTypes.h"
        #include "GdiplusInit.h"
        #include "GdiplusPixelFormats.h"
        #include "GdiplusColor.h"
        #include "GdiplusMetaHeader.h"
        #include "GdiplusImaging.h"
        #include "GdiplusColorMatrix.h"    // The rest of these are used only by the application    #include "GdiplusGpStubs.h"
        #include "GdiplusHeaders.h"    namespace DllExports
        {
            #include "GdiplusFlat.h"
        };
        #include "GdiplusImageAttributes.h"
        #include "GdiplusMatrix.h"
        #include "GdiplusBrush.h"
        #include "GdiplusPen.h"
        #include "GdiplusStringFormat.h"
        #include "GdiplusPath.h"
        #include "GdiplusLineCaps.h"
        #include "GdiplusMetafile.h"
        #include "GdiplusGraphics.h"
        #include "GdiplusCachedBitmap.h"
        #include "GdiplusRegion.h"
        #include "GdiplusFontCollection.h"
        #include "GdiplusFontFamily.h"
        #include "GdiplusFont.h"
        #include "GdiplusBitmap.h"
        #include "GdiplusImageCodec.h"}; // namespace Gdiplus
    这句话左看右看都不像是有错的啊,而且还是SDK中的原话
    程序是公司以前留下来的,我们就在基础上改的,应该也没错,毕竟用了这么久
    不加gdiplus.h就没有任何错误的
    但是新建一个小型的程序,用GDI+的话就没错,为什么呢,崩溃ing
      

  10.   

    我怀疑你的大工程中并未包含gdiplus.h所在的目录,在工程属性的c++包含目录里看看
      

  11.   

    如果你单纯只是 png 的话,用 CImage 就足够了。
    它内部会自动调用 GDI+ 对象。
    如果你要显示 gif 动画,则必须自己调用 GDI+http://blog.csdn.net/DavidHsing/archive/2009/03/24/4020197.aspx
      

  12.   

    注意先
        //Startup Gdiplus
        GdiplusStartupInput gpGdiPlusStartupInput;
        GdiplusStartup(&m_gpGdiPlusToken, &gpGdiPlusStartupInput, NULL);
      

  13.   

    忘记给你声明了:ULONG_PTR        m_gpGdiPlusToken;
      

  14.   

    有两种解决办法:    1.在stdafx.h中去掉WIN32_LEAN_AND_MEAN的定义
        2.在stdafx.h中包含#include <comdef.h>
      

  15.   

    chenyu2202863按你的方法做了怎么有这样的错误呢Compiling...
    windraw.c
    e:\导航组\audioapp_n9\src\auimain\stdafx.h(1) : warning C4005: 'UNICODE' : macro redefinition
            unknown(0) : see previous definition of 'UNICODE'
    c:\program files\microsoft visual studio\vc98\include\comdef.h(17) : fatal error C1189: #error :  Native Compiler support only available in C++ compiler
    Error executing cl.exe.我的头文件是这样申明的
    #define UNICODE
    #ifndef ULONG_PTR
    #define ULONG_PTR unsigned long*
    #endif#include <windows.h>
    #include <comdef.h> #include "c:\gdi+\includes\gdiplus.h" 
    using namespace Gdiplus; 
    #pragma comment(lib, "c:\\gdi+\\lib\\gdiplus.lib")
    各位大虾指点一下哪里不对??
      

  16.   

    DavidHsing 大虾
    CImage是C++的类吧,C中不能用吧,C也没有虾米继承机制
      

  17.   

    C,当然不支持namespace,你先看看GDI+的API再说吧,用其GDI+ Flat API而不是类库。
      

  18.   

    LSS的MACKZ具体咋用呢,偶素菜鸟级别,以前都没学过C的,只学过C++ and .net
      

  19.   

    在Visual C++.NET使用GDI+一般遵循下列步骤:   (1)、在应用程序中添加GDI+的包含文件gdiplus.h以及附加的类库gdiplus.lib。通常gdiplus.h包含文件添加在应用程序的 stdafx.h文件中,而gdiplus.lib可用两种进行添加:第一种是直接在stdafx.h文件中添加下列语句:#pragma comment( lib, "gdiplus.lib" )
      另一种方法是:选择"项目->属性"菜单命令,在弹出的对话框中选中左侧的"链接器->输入"选项,在右侧的"附加依赖项"框中键入gdiplus.lib, (2)、在应用程序项目的应用类中,添加一个成员变量,如下列代码:ULONG_PTR m_gdiplusToken;
    其中,ULONG_PTR是一个DWORD数据类型,该成员变量用来保存GDI+被初始化后在应用程序中的GDI+标识,以便能在应用程序退出后,引用该标识来调用Gdiplus:: GdiplusShutdown来关闭GDI+。(3)、在应用类中添加ExitInstance的重载,并添加下列代码用来关闭GDI+:int CGDIPlusApp::ExitInstance(){ Gdiplus::GdiplusShutdown(m_gdiplusToken); return CWinApp::ExitInstance();}(4)、在应用类的InitInstance函数中添加GDI+的初始化代码: 
    BOOL CGDIPlusApp::InitInstance(){ CWinApp::InitInstance(); Gdiplus::GdiplusStartupInput gdiplusStartupInput; Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL); ...}
      

  20.   


    你都有向导生成的 “stdafx.h” 了,还是 Win32 啊??
      

  21.   

    貌似你说的好像是C++的语法,但是却一直在申明是C的工程,如果是C++,那你的问题就好办了,两种情况我都遇到了,我这有两个解决的办法可以解决。你先确认下工程到底是C的,还是C++的吧
      

  22.   


    VS2008 是在“工具”->“选项”->“项目和解决方案”->“VC++ 目录”
      

  23.   

    我知道  qq406597093  msn  [email protected]
      

  24.   

    大侠幸苦了
    不过偶用的是vc6.0不是.NET
    也不是C++的工程,是C
      

  25.   

    是CCCCCCCCCCCCCCCCCCCCCCCCCC
    NOT C+++++++++++
    准确的说是win32 的c
    是不是不能用GDI+??不支持??
      

  26.   

    缺少COM支持:
    使用以下两种方法:
    1.在“stdafx.h”文件中添加以下内容:
    #include   <comdef.h> 或者
    2#define WIN32_LEAN_AND_MEAN 注释掉,它排除了#include   <comdef.h> 的com定义支持。
      

  27.   

    即使是VC6,貌似也只有WIN32 SDK方式和MFC之分,
    哪还有C和C++之分?那你写
    int c;
    c++;
    看能不能通过
      

  28.   

    你用CImage 它不是WIN32里面的类 需要导入#include <afxwin.h>
    才能使用 
    win32认得namespace 你用的c++ 也支持命名空间 
    vc6.0   默认没有   gdi+   的,只有下载一个来装。 
     你是在函数里面用它吗?
      声明拉吗?
    用using声明:void func(){using namespace alex;//using指令using chris::love;//uisng声明love();//chirs::love();alex::love();//
     
     是这样的答案?
      

  29.   

    C不支持namespace,编译不过不是正常的么?