• <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>

            EverSpring working shop

            To pursue creative ideas based on nature.

            統(tǒng)計

            留言簿(1)

            他山之石

            閱讀排行榜

            評論排行榜

            The BMP2TXT conveter (From the network)



             1
             // bmp_converter_2.cpp : Defines the entry point for the application.
             2 //
             3 
             4 #include "stdafx.h"
             5 // Primitive BMP to ASCII art generator
             6 // Reads source.bmp and outputs art.txt
             7 // Source must be 24-bit .bmp
             8 
             9 #include <iostream.h>
            10 #include <windows.h>
            11 
            12 #define MAX_SHADES 10
            13 
            14 BITMAPFILEHEADER bfh;
            15 BITMAPINFOHEADER bih;
            16 RGBTRIPLE *image;
            17 DWORD written;
            18 HANDLE hfile;
            19 int imagesize;
            20 char shades[MAX_SHADES] = {'#','$','O','=','+','|','-','^','.',' '};
            21 char return1 = 0x0D;
            22 char return2 = 0x0A;
            23 int needle = 0;
            24 int average_color = 0;
            25 
            26 int APIENTRY WinMain(HINSTANCE hInstance,
            27                      HINSTANCE hPrevInstance,
            28                      LPSTR     lpCmdLine,
            29                      int       nCmdShow)
            30 {
            31      // Open a channel to source file
            32      hfile = CreateFile("source.bmp",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,NULL,NULL);
            33      // Read header
            34      ReadFile(hfile,&bfh,sizeof(bfh),&written,NULL);
            35      ReadFile(hfile,&bih,sizeof(bih),&written,NULL);
            36      // Read image
            37      imagesize = bih.biSizeImage;
            38      image = new RGBTRIPLE[imagesize];
            39      ReadFile(hfile,image,imagesize*sizeof(RGBTRIPLE),&written,NULL);
            40      // Close source file
            41      CloseHandle(hfile);
            42      // Open channel to output
            43      hfile = CreateFile("art.txt",GENERIC_WRITE,NULL,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
            44      // Keeping in mind the image is upside down, convert and write it
            45      // It down-samples the image a bit in res too
            46      for(int y = bih.biHeight-1;y >= 0;y--)
            47      {
            48           for(int x = 0;x < bih.biWidth;x++)
            49           {
            50                // Get the average color
            51                 average_color = (image[x+y*bih.biWidth].rgbtBlue+image[x+y*bih.biWidth].rgbtRed+image[x+y*bih.biWidth].rgbtGreen)/3;
            52                // Convert to a shade of 8
            53                average_color /= (256/MAX_SHADES);
            54                if(average_color >= MAX_SHADES)
            55                     average_color -= 1;
            56                // Output
            57                WriteFile(hfile,&shades[average_color],1,&written,NULL);
            58                //WriteFile(hfile,&shades[average_color],1,&written,NULL);
            59           }
            60           WriteFile(hfile,&return1,1,&written,NULL);
            61           WriteFile(hfile,&return2,1,&written,NULL);
            62      }
            63      // Close handle to output
            64      CloseHandle(hfile);
            65      return 0;
            66 }
            67 
            68 

            This code is just a rough implementation to convert a small .bmp file to text file.
            It needs to be improved to be fit with bigger file or monofile. 

            Compile and debug tool: VC++ 6, Win32 Simple Application.

            Below is the testing result. The output txt file is often italic if the width is not dividable by 8 well.

            Source.bmp (Must be placed in the project directory)

            Output txt displayed as(only a small part of the whole pic):
                                                
                                        #        
                                =#########=      
                            ###############-     
                           -###############=     
                    =#####  ###############-     
               =##########= -######-             
               ###########=    -###=             
               =#########=     =###- =#=         
                -#######       #########-        
                  -####=    -###########=        
                   -###-    =#######=####        
                   -###-    #####=  -####        
                   -###-   -####  -=-####-       
                   -###=   -########-####-       
                   -###=   -#######--####-       
                   -###=   -###-    -####-       
                   -###=   =###--###=####=       
                   -###=   =#############=       
                   -###=   =####### -####=       
                   =###-   =###=    =####-       
                   =###-   -###= -#######-       
                  -####-    #############-       
                 -#####     =############-       
                ######=     -####  ######        
                #####-      ####   #####=        
                =##-       ####    -#####=       
                          =###      -#####=      
                         -###        -#####-     
                         -#-          =####-     
                                       =##=      
                                        ##-
                  
                                                 


            posted on 2007-10-14 22:50 everspring79 閱讀(409) 評論(0)  編輯 收藏 引用 所屬分類: Snippet

            香蕉99久久国产综合精品宅男自 | 久久亚洲AV无码精品色午夜| AA级片免费看视频久久| 国产精品xxxx国产喷水亚洲国产精品无码久久一区| 99久久超碰中文字幕伊人| 久久精品国产精品青草app| 人人狠狠综合久久亚洲高清| 久久精品国产乱子伦| 久久99国产精品久久99果冻传媒| 久久久久亚洲?V成人无码| 久久青青草原精品国产| 久久久久99精品成人片三人毛片| 久久久久久精品无码人妻| 九九99精品久久久久久| 国产色综合久久无码有码| 国产成人精品久久一区二区三区| 日本精品久久久久影院日本| 狠狠88综合久久久久综合网| 亚洲精品无码久久久久AV麻豆| 国产高潮国产高潮久久久| 久久久久se色偷偷亚洲精品av| 99久久人人爽亚洲精品美女| 久久99精品国产麻豆| 狠狠色丁香久久婷婷综合| 欧美色综合久久久久久| 精品久久久久国产免费| 久久国产精品99精品国产987| 囯产精品久久久久久久久蜜桃| 国产日韩久久久精品影院首页| 99久久久精品| 久久精品人人做人人爽97| 久久SE精品一区二区| 国产精品久久久久久久久软件| 国产精品VIDEOSSEX久久发布 | 久久亚洲电影| 国内精品久久久久久久久 | 一本久久免费视频| 亚洲国产成人精品女人久久久 | 日韩精品久久久久久| 久久久久久人妻无码| 久久无码中文字幕东京热|