• <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| 中文字幕无码av激情不卡久久 | 99久久中文字幕| 性高湖久久久久久久久| 亚洲人成精品久久久久| 伊人热人久久中文字幕| 国产精品久久新婚兰兰| 777米奇久久最新地址| 午夜精品久久久内射近拍高清| 久久久久成人精品无码中文字幕| 精品一久久香蕉国产线看播放 | 精品久久人妻av中文字幕| 久久AⅤ人妻少妇嫩草影院| 一本一本久久a久久综合精品蜜桃| 久久精品国产影库免费看| 思思久久99热只有频精品66| 91久久香蕉国产熟女线看| 久久久国产99久久国产一| 嫩草影院久久国产精品| 久久亚洲中文字幕精品有坂深雪| 久久强奷乱码老熟女| 久久电影网一区| 99久久久国产精品免费无卡顿| 色综合久久夜色精品国产| 久久精品国产亚洲精品| 99久久精品免费观看国产| 99久久精品国产高清一区二区 | 国产91色综合久久免费| 无码国内精品久久人妻蜜桃 | 久久综合综合久久综合| 噜噜噜色噜噜噜久久| 久久精品成人免费国产片小草| 久久91精品久久91综合| 97久久超碰国产精品2021| 婷婷综合久久中文字幕蜜桃三电影| 大香伊人久久精品一区二区 | 97久久超碰成人精品网站| 国产成人精品白浆久久69| 99国产精品久久|