• <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网站| 久久婷婷五月综合色高清| 久久久久久久久无码精品亚洲日韩 | 欧美黑人激情性久久| 久久精品中文字幕无码绿巨人 | 国色天香久久久久久久小说| 久久婷婷五月综合色奶水99啪| 国产日产久久高清欧美一区| 亚洲色欲久久久久综合网| 久久久国产打桩机| 精品久久久久久无码中文野结衣 | 久久只这里是精品66| 亚洲国产精品久久久久久| 亚洲国产精品无码久久98| 伊人久久精品影院| 久久国产精品成人免费| 久久精品国产男包| 精品视频久久久久| 久久99久久99小草精品免视看| 久久久亚洲AV波多野结衣| 久久97久久97精品免视看秋霞| 久久99热只有频精品8| 少妇内射兰兰久久| 日韩电影久久久被窝网| 97精品国产97久久久久久免费| 久久香蕉国产线看观看精品yw | 久久久久久精品免费看SSS | 九九精品99久久久香蕉| 亚洲AV乱码久久精品蜜桃| 一级女性全黄久久生活片免费 | 乱亲女H秽乱长久久久| 一级做a爰片久久毛片免费陪| 久久99久久成人免费播放| 久久婷婷综合中文字幕| 天天综合久久久网| 国产V综合V亚洲欧美久久| 老色鬼久久亚洲AV综合| 久久久久99精品成人片试看| 久久综合狠狠综合久久综合88| 亚洲精品无码久久久久|