logo资料库

android自动滑块验证码.docx

第1页 / 共5页
第2页 / 共5页
第3页 / 共5页
第4页 / 共5页
第5页 / 共5页
资料共5页,全文预览结束
final static Point POINT_SLIDER = new Point(218, 1042);//滑块坐标点 final int grayPercent = 5; final int bgx = 42; final int bgy = 390; final int bgw = 1000; final int bgh = 570; final int shadowx = 112; final int rightX = 435; final int shadowSize = 126; //检索的最小灰色百分比 //贴图左上角相对于全屏截图的x //贴图左上角相对于全屏截图的y //贴图宽 //贴图高 //起点相对于贴图的x //检索右边区域相对于贴图的起始x //灰块宽 Bitmap mBitmapScreen0; Bitmap mBitmapScreen1; int mPixels0[]; int mPixels1[]; int mGrayPixels0[]; int mSrcX, mSrcY, mSrcH; int mMoveX; void doFind() { //滑块禁止时的截图 //滑块滑动以后的截图 //滑块禁止时的截图的像素值 //滑块滑动以后的截图像素值 //mBitmapScreen0灰质以后的像素值 //找到的起始滑块位置与高度 //找到的要移动到的位置 long t = System.currentTimeMillis(); boolean bLoadOk = loadImage(); Log.e("Test", "bLoadOk = "+ bLoadOk); if(!bLoadOk) { //脚本退出 mActionList.add(new ExitAppAction(5000)); return; } if(findXY()) { if(findMoveX()) { Log.e("Test", "find moveX ok! x = "+mMoveX); //脚本滑 SwipAction saUp = new SwipAction(POINT_SLIDER.x, POINT_SLIDER.y, mMoveX + shadowSize/2, POINT_SLIDER.y-10+GlobalState.instance().getRandomInt(20), 200, GlobalState.instance().getRandomMSec(2000)); saUp.setSendEventCmd(ScriptHelper.PHONE_N5); mActionList.add(saUp); } } Log.e("Test", "use time = " + (System.currentTimeMillis() - t)); } Bitmap loadBitmap(String path) {
File mFile = new File(path); if (mFile.exists()) { Bitmap bitmap = BitmapFactory.decodeFile(path); return bitmap; } return null; } boolean loadImage() { mBitmapScreen0 = loadBitmap(Environment.getExternalStorageDirectory()+"/shoot0.png"); mBitmapScreen1 = loadBitmap(Environment.getExternalStorageDirectory()+"/shoot1.png"); boolean bok = mBitmapScreen0 != null && mBitmapScreen1 != null; if(bok) { mPixels0 = new int[mBitmapScreen0.getWidth()*mBitmapScreen0.getHeight()]; mPixels1 = new int[mBitmapScreen1.getWidth()*mBitmapScreen1.getHeight()]; mBitmapScreen0.getPixels(mPixels0, 0, mBitmapScreen0.getWidth(), 0, 0, mBitmapScreen0.getWidth(), mBitmapScreen0.getHeight()); mBitmapScreen1.getPixels(mPixels1, 0, mBitmapScreen1.getWidth(), 0, 0, mBitmapScreen1.getWidth(), mBitmapScreen1.getHeight()); Bitmap grayImg = grey(mBitmapScreen0); mGrayPixels0 = new int[grayImg.getWidth()*grayImg.getHeight()]; grayImg.getPixels(mGrayPixels0, 0, grayImg.getWidth(), 0, 0, grayImg.getWidth(), grayImg.getHeight()); grayImg = null; } return bok; } public Bitmap grey(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); Bitmap faceIconGreyBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(faceIconGreyBitmap); Paint paint = new Paint(); ColorMatrix colorMatrix = new ColorMatrix(); colorMatrix.setSaturation(0);
ColorMatrixColorFilter colorMatrixFilter = new ColorMatrixColorFilter(colorMatrix); paint.setColorFilter(colorMatrixFilter); canvas.drawBitmap(bitmap, 0, 0, paint); return faceIconGreyBitmap; } int getDH(int x, int y) { for(int ty = y; ty <= y + 300; ty++) { int pixel0 = mPixels0[getPixelPos(x, ty)]; int pixel1 = mPixels1[getPixelPos(x, ty)]; if (pixel0 == pixel1) { int sameH = getSameH(x, ty); if(sameH > 50) { return ty - y; } } } return 0; } int getSameH(int x, int y) { int r = 0; for(int ty = y; ty <= y + 100; ty++) { int pixel0 = mPixels0[getPixelPos(x, ty)]; int pixel1 = mPixels1[getPixelPos(x, ty)]; if (pixel0 == pixel1) { r++; } else { return r; } } return r; } boolean findMoveX() { //x 找点 灰度大于 int startx = bgx + rightX; int y = mSrcY; int maxPer = 0; for(int x = startx; x < bgx + bgw - shadowSize; x++) { int r = checkAreaGray(x, y); if(r >= maxPer && r >= grayPercent) { maxPer = r;
mMoveX = x; } } return maxPer != 0; } int checkAreaGray(int dx, int dy) { int grayCount = 0; for (int tx = 0; tx 0x505050 && pixelstart - shadow < ty)]; 0xa0a0a0) { grayCount++; } } } int per = grayCount * 100 / (shadowSize * mSrcH); //Log.e("Test", "checkAreaGray per = " + per); return per; } boolean findXY() { int startx = bgx + shadowx; int dh = 0; for(int x = startx; x < startx + shadowSize; x++) { for(int y = bgy; y <= bgy + bgh - shadowSize; y++) { int pixel0 = mPixels0[getPixelPos(x, y)]; int pixel1 = mPixels1[getPixelPos(x, y)]; if(pixel0 != pixel1) { mSrcX = x; mSrcY = y + 8; dh = getDH(mSrcX, mSrcY); mSrcH = dh - 24; Log.e("Test", "findXY() ok! x=" + mSrcX + " y=" + mSrcY + " h=" + mSrcH); return true; } } } return false; }
int getPixelPos(int x, int y) { return y*mBitmapScreen0.getWidth()+x; }
分享到:
收藏