• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            數據加載中……

            [wxWidgets]Embedding PNG images into executables(將png嵌入到程序中)

            首先需要用工具將png圖片轉成.cpp或者.h文件
            工具:bin2c
            源代碼:

            // bin2c.c
            //
            // convert a binary file into a C source vector
            //
            // THE "BEER-WARE LICENSE" (Revision 3.1415):
            // sandro AT sigala DOT it wrote this file. As long as you retain this notice you can do
            // whatever you want with this stuff.  If we meet some day, and you think this stuff is
            // worth it, you can buy me a beer in return.  Sandro Sigala
            //
            // syntax:  bin2c [-c] [-z] <input_file> <output_file>
            //
            //          -c    add the "const" keyword to definition
            //          -z    terminate the array with a zero (useful for embedded C strings)
            //
            // examples:
            //     bin2c -c myimage.png myimage_png.cpp
            //     bin2c -z sometext.txt sometext_txt.cpp

            #include 
            <ctype.h>
            #include 
            <stdio.h>
            #include 
            <stdlib.h>
            #include 
            <string.h>

            #ifndef PATH_MAX
            #define PATH_MAX 1024
            #endif

            int useconst = 0;
            int zeroterminated = 0;

            int myfgetc(FILE *f)
            {
                
            int c = fgetc(f);
                
            if (c == EOF && zeroterminated)
                
            {
                    zeroterminated 
            = 0;
                    
            return 0;
                }

                
            return c;
            }


            void process(const char *ifname, const char *ofname)
            {
                FILE 
            *ifile, *ofile;
                errno_t err 
            = fopen_s(&ifile,ifname,"rb");
                
            if (ifile == NULL)
                
            {
                    fprintf(stderr, 
            "cannot open %s for reading\n", ifname);
                    exit(
            1);
                }

                fopen_s(
            &ofile,ofname, "wb");
                
            if (ofile == NULL)
                
            {
                    fprintf(stderr, 
            "cannot open %s for writing\n", ofname);
                    exit(
            1);
                }

                
            char buf[PATH_MAX], *p;
                
            const char *cp;
                
            if ((cp = strrchr(ifname, '/')) != NULL)
                
            {
                    
            ++cp;
                }
             else {
                    
            if ((cp = strrchr(ifname, '\\')) != NULL)
                        
            ++cp;
                    
            else
                        cp 
            = ifname;
                }

                strcpy_s(buf, cp);
                
            for (p = buf; *!= '\0'++p)
                
            {
                    
            if (!isalnum(*p))
                        
            *= '_';
                }

                fprintf(ofile, 
            "static %sunsigned char %s[] = {\n", useconst ? "const " : "", buf);
                
            int c, col = 1;
                
            while ((c = myfgetc(ifile)) != EOF)
                
            {
                    
            if (col >= 78 - 6)
                    
            {
                        fputc(
            '\n', ofile);
                        col 
            = 1;
                    }

                    fprintf(ofile, 
            "0x%.2x, ", c);
                    col 
            += 6;
                }

                fprintf(ofile, 
            "\n};\n");

                fclose(ifile);
                fclose(ofile);
            }


            void usage(void)
            {
                fprintf(stderr, 
            "usage: bin2c [-cz] <input_file> <output_file>\n");
                exit(
            1);
            }


            int main(int argc, char **argv)
            {
                
            while (argc > 3)
                
            {
                    
            if (!strcmp(argv[1], "-c"))
                    
            {
                        useconst 
            = 1;
                        
            --argc;
                        
            ++argv;
                    }
             else if (!strcmp(argv[1], "-z"))
                    
            {
                        zeroterminated 
            = 1;
                        
            --argc;
                        
            ++argv;
                    }
             else {
                        usage();
                    }

                }

                
            if (argc != 3)
                
            {
                    usage();
                }

                process(argv[
            1], argv[2]);
                
            return 0;
            }

            在官方論壇中的做了些修改。去掉了一些警告信息。

            2、在你的程序中包含轉換好的cpp或者h
             #include <myimage_png.cpp>

            wxMemoryInputStream istream(myimage_png, sizeof myimage_png);
            wxImage myimage_img(istream, wxBITMAP_TYPE_PNG);

            或者可以定義個宏

            #define wxGetBitmapFromMemory(name) _wxGetBitmapFromMemory(name ## _png, sizeof(name ## _png))
            inline wxBitmap _wxGetBitmapFromMemory(const unsigned char *data, int length) {
            wxMemoryInputStream is(data, length);
            return wxBitmap(wxImage(is, wxBITMAP_TYPE_ANY, -1), -1);
            }
            
            注意:要確保png的句柄初始化了。wxImage::AddHandler(new wxPNGHandler);
            

            posted on 2009-12-04 11:07 Stone xin 閱讀(534) 評論(0)  編輯 收藏 引用

            国产亚洲色婷婷久久99精品| 国产精品久久久久久福利69堂| 国产69精品久久久久99| 久久精品国产第一区二区| 久久综合亚洲色HEZYO国产| 久久人做人爽一区二区三区| 久久亚洲日韩精品一区二区三区 | 亚洲精品高清国产一线久久| 伊人久久大香线蕉综合Av| 国产精品久久永久免费| 亚洲美日韩Av中文字幕无码久久久妻妇 | 国产欧美久久久精品影院| 久久亚洲精品人成综合网| 国产免费福利体检区久久| 亚洲中文字幕久久精品无码喷水 | 伊人久久大香线蕉亚洲五月天| 国产99久久精品一区二区| 久久亚洲AV成人无码| 久久福利片| 97久久精品人人做人人爽| 丁香色欲久久久久久综合网| 国产福利电影一区二区三区,免费久久久久久久精 | 久久亚洲国产成人影院| 国产 亚洲 欧美 另类 久久| 色欲久久久天天天综合网精品| 久久av免费天堂小草播放| 性欧美大战久久久久久久久| 免费一级做a爰片久久毛片潮| 香港aa三级久久三级| 潮喷大喷水系列无码久久精品 | 亚洲愉拍99热成人精品热久久| 日本加勒比久久精品| 国产精品久久久天天影视香蕉| 精品久久久久久综合日本| 久久久久成人精品无码中文字幕 | 亚洲国产另类久久久精品小说| 青青草原综合久久大伊人导航| 久久精品国产色蜜蜜麻豆| 国产精品一区二区久久精品无码| 72种姿势欧美久久久久大黄蕉| 久久精品国产网红主播|