資源描述:
《驗證碼識別封裝類》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、using?System;using?System.Collections.Generic;using?System.Text;using?System.Collections;using?System.Drawing;using?System.Drawing.Imaging;using?System.Runtime.InteropServices;namespace?BallotAiying2{????class?UnCodebase????{????????public?Bitmap?bmpobj;????????public?UnCodebase(Bitmap?pic)????????{
2、????????????bmpobj?=?new?Bitmap(pic);????//轉(zhuǎn)換為Format32bppRgb????????}????????///?????????///?根據(jù)RGB,計算灰度值????????///?????????///?Color值????????///?灰度值,整型????????private?int?GetGrayNumColor(System.Drawing.Color?posClr)????????{????????
3、????return?(posClr.R?*?19595?+?posClr.G?*?38469?+?posClr.B?*?7472)?>>?16;????????}????????///?????????///?灰度轉(zhuǎn)換,逐點方式????????///?????????public?void?GrayByPixels()????????{????????????for?(int?i?=?0;?i?
4、h;?j++)????????????????{????????????????????int?tmpValue?=?GetGrayNumColor(bmpobj.GetPixel(j,?i));????????????????????bmpobj.SetPixel(j,?i,?Color.FromArgb(tmpValue,?tmpValue,?tmpValue));????????????????}????????????}????????}????????///?????????///?去圖形邊框????????///?????????///?5、ram?name="borderWidth">????????public?void?ClearPicBorder(int?borderWidth)????????{????????????for?(int?i?=?0;?i?
6、
7、?j?
8、
9、?j?>?bmpobj.W
10、idth?-?1?-?borderWidth?
11、
12、?i?>?bmpobj.Height?-?1?-?borderWidth)????????????????????????bmpobj.SetPixel(j,?i,?Color.FromArgb(255,?255,?255));????????????????}????????????}????????}????????///?????????///?灰度轉(zhuǎn)換,逐行方式????????///?????????public?void?GrayByLine()????????{????????????Recta
13、ngle?rec?=?new?Rectangle(0,?0,?bmpobj.Width,?bmpobj.Height);????????????BitmapData?bmpData?=?bmpobj.LockBits(rec,?ImageLockMode.ReadWrite,?bmpobj.PixelFormat);//?PixelFormat.Format32bppPArgb);????????