Demo:
Using System; Using System. Collections. Generic; Using System. LINQ; Using System. text; Using System. drawing; Using System. IO; Namespace Leleapplication1 { Class Myimage { // Images to be analyzed Private Bitmap bmpobj; // The number comparison string to be inherited and rewritten. This is used in the subclass to compare numbers. Public Dictionary < String , Char > Numdic = New Dictionary < String , Char > (); // Returns the gray value of a point in the image. Private Int Getgraynumcolor (system. Drawing. Color posclr ){ Return (Posclr. R * 19595 + Posclr. g * 38469 + Posclr. B * 7472 )> 16 ;} // Grayscale Processing Private Void Graybypixels (){ For ( Int I = 0 ; I <bmpobj. height; I ++ ){ For ( Int J = 0 ; J <bmpobj. width; j ++ ){ Int Tmpvalue =Getgraynumcolor (bmpobj. getpixel (J, I); bmpobj. setpixel (J, I, color. fromargb (tmpvalue, tmpvalue, tmpvalue ));}}} // Get 01 of an imageCodeSequence Private String Getsinglebmp code (Bitmap singlepic, Int Dggrayvalue) {color piexl; String Code = "" ; For (Int Posy = 0 ; Posy <singlepic. height; posy ++ ) For ( Int Posx = 0 ; Posx <singlepic. width; posx ++ ) {Piexl = Singlepic. getpixel (posx, Posy ); If (Piexl. r <dggrayvalue) // Color. Black) Code = code +" 1 " ; Else Code = Code + " 0 " ;} Return Code ;} // Get several small numbers from an image. Private Bitmap [] getpicvalidbyvalue (Int Dggrayvalue) {list <Bitmap> piclist = New List <bitmap> (); Rectangle clonerect; Int Posx1 = bmpobj. Width, posy1 = bmpobj. Height, posx2 = 0 , Posy2 = 0 ; Bool Cut = False ; Int Last =-1 , Lastx = 0 ; For ( Int J = 0 ; J <bmpobj. width; j ++) // Find valid zone {Cut = False ; For ( Int I = 0 ; I <bmpobj. height; I ++ ){ Int Pixelvalue = Bmpobj. getpixel (J, I). R; If (Pixelvalue <dggrayvalue) // Based on the gray value { If (Posx1> J) posx1 = J; If (Posy1> I) posy1 = I; If (Posx2 <j) posx2 = J; If (Posy2 <I) posy2 = I; cut = True ;}}; If (CUT) Continue ; If (Last + 1 =J) {last ++ ; Continue ;} Clonerect = New Rectangle (posx1, posy1, posx2-posx1 + 1 , Posy2-posy1 + 1 ); Lastx = J; last = J; posx1 = Bmpobj. width; posy1 =Bmpobj. height; posx2 = 0 ; Posy2 = 0 ; Piclist. Add (bmpobj. Clone (clonerect, bmpobj. pixelformat )); // Copy a small image }; Return Piclist. toarray ();} // Returns the numeric string of an image. Private String Getpicnumber () {graybypixels (); // Grayscale Processing Bitmap [] pics = getpicvalidbyvalue ( 128 ); // Get valid value Stringbuilder sb = New Stringbuilder (); Char C; For ( Int I = 0 ; I <pics. length; ++I ){ String Code = getsinglebmp code (PICS [I], 128 ); // Get code string If (Numdic. trygetvalue (code, Out C) {sb. append (c );}} Return SB. tostring ();} // Obtain a digital string of the image by calling the API. Public String Getpicnum (Bitmap pic) {bmpobj = New Bitmap (PIC ); // Convert to format32bpprgb Return Getpicnumber ();} // Obtain the numeric string (reload) of an image by calling the API) Public String Getpicnum ( String Filename) {bmpobj =New Bitmap (filename ); Return Getpicnumber ();} // Output The number found in a graph. It is used to test or find the number comparison string. Private Void Testnumber () {graybypixels (); // Grayscale Processing Bitmap [] pics = getpicvalidbyvalue ( 128 ); // Get valid value For ( Int I = 0 ; I <pics. length; ++ I ){ String Code = getsinglebmp code (PICS [I], 128 ); // Get code string Console. writeline (I); console. writeline (CODE );}} // An external call is used to output the numbers found in a graph. Public Void Testnum (Bitmap pic) {bmpobj = New Bitmap (PIC ); // Convert to format32bpprgb Testnumber ();} // An external call is used to output the numbers found in a graph. It is used to test or find a number comparison string (reload) Public Void Testnum ( String Filename) {bmpobj = New Bitmap (filename); testnumber ();}} Class Jingdongimage: myimage { Public Jingdongimage (){ // Numdic. Add ("111101111011100110001110100001110100000111000000111000001111100000111000000111100", '¥ '); Numdic. Add ( " 011110110011110011110011110011110011110011011110 " , ' 0 ' ); Numdic. Add ( " 01101110011001100110011001101111 " , ' 1 ' ); Numdic. Add ( " 011110110011000011000110001100011000110000111111 " , ' 2 ' ); Numdic. Add ( " 011110110011000011001110000011000011110011011110 " , ' 3 ' ); Numdic. Add ( " 000010000110001110010110100110111111000110000110 " , ' 4 ' ); Numdic. Add ( " 011111011000011000011110000011000011110011011110 " , ' 5 ' ); Numdic. Add ( " 001110011000110000111110110011110011110011011110 " , ' 6 ' ); Numdic. Add ( " 111111000011000110000110001100001100011000011000 " , ' 7 ' ); Numdic. Add ( " 011110110011110011011110110011110011110011011110 " , ' 8 ' ); Numdic. Add ( " 011110110011110011110011011111000011000110011100 " , ' 9 ' ); Numdic. Add ( " 1111 " , ' . ' );}} Class Program { Static Void Main ( String [] ARGs) {directoryinfo dinfo = New Directoryinfo ( @" D:/Images " ); Jingdongimage Test = New Jingdongimage (); Foreach ( VaR File In Dinfo. getfiles () {console. writeline (file. fullname); console. writeline (test. getpicnum (file. fullname) ;}console. Readline ();}}}