案例:微信跳一跳

#adb工具的简单指令

1、截图(只能保存png格式的图片)

adb shell screencap -p /sdcard/screen.png //截图 到剪切板,命名为screen.png

adb pull /sdcard/screen.png //将剪切板的图片输出加载到当前文件夹下,默认名字为screen.png。

2、按压手机屏幕

adb shell input swipe 200 200 195 195 650(通过adb输入一个指令input swipe(按压),按压坐标为200,200,抬手坐标为195,195,按压时长能够为650ms)

#easyx 贴图(graphics.h头文件)

initgraph(900,900);//创建宽度900,高度900的显示界面,单位:px像素。

system("pause")

1、定义:IMAGE img;(IMAGE图片类型,img图片名字)

2、加载:loadimage(&img,"8.bmp");//加载图片,把8.bmp图片放到img空间中。注:加载图片只能加载.jpg .bmp格式的图片,.png不行

3、显示:putimage(0,0, &img);//将img里卖弄存放的图片显示在0,0坐标

步骤:

1、获取手机实时画面

system("adb shell screencap -p /sdcard/screen.png");

system("adb pull /sdcard/screen.png");

//修改图片格式

CImage cimage;

cimage.Load("screen.png");

cimage.Save("screen.jpg");

//创建显示界面      显示控制台

initgraph(900,900,SHOWCONSOLE);

//定义加载显示图片

IMAGE Screen,img;

loadimage(&Screen,"screen.jpg");

//裁剪图片

SetWorkingImage(&Screen);

getimage(&img,100,800,900,900);//裁剪图片

SetWorkingImage(NULL);//结束裁剪

putimage(0,0, &img);

2、获取起点坐标(RGB:55,60,100)

int x,y;//表示人物的坐标

for(y=899;y>=0;y--)

{	int flag=0;

	for(x=0;x<900;x++){

		if(RGB(55,60,100)==getpixel(x,y)) //根据坐标返回该坐标的颜色

 	{

			flag=1;

			break;

		}

	}

   if(flag) break;

}

printf("起点坐标为:%d,%d",x,y);

3、获取终点坐标

COLORREF bk=getpixel(10,10);//获取背景颜色
int dx,dy;//表示人物终点坐标
for(dy=899;dy>=0;dy--)

{	int flag=0;

	for(dx=0;dx<900;dx++){

		if(Similar(bk,getpixel(dx,dy))>25) //根据坐标返回该坐标的颜色

		{

			flag=1;

			break;

		}

	}

   if(flag) break;

}
printf("起点坐标为:%d,%d",dx,dy);		

4、根据两点求取距离长度

double d=sqrt(double((x-dx)*(x-dx)+(y-dy)*(y-dy)));

5、根据距离/速度得到按压时长

double time=d*1;//速度需要测量

6、根据时长模拟人物按压手机屏幕使之跳跃

char Str[128];
sprintf(Str,"adb shell input swipe 200 200 195 195 %d",(int)time);//字符串拼接函数
system(Str);//执行跳跃命令

完整代码:

#include <stdio.h>
#include <windows.h>
#include <graphics.h>
#include <atlimage.h>
#include <math.h>

double Similar(COLORREF color1, COLORREF color2);//函数的声明
int main()
{
	while (1)
	{
		system("adb shell screencap -p /sdcard/screen.png");
		system("adb pull /sdcard/screen.png");
		CImage cimage;
		cimage.Load("screen.png");
		cimage.Save("screen.jpg");
		initgraph(900, 900, SHOWCONSOLE);
		IMAGE Screen, img;
		loadimage(&Screen, "screen.jpg");
		SetWorkingImage(&Screen);
		getimage(&img, 100, 800, 900, 900);
		SetWorkingImage(NULL);
		putimage(0, 0, &img);
		int x, y;//表示人物的坐标
		for (y = 899;y >= 0;y--)
		{
			int flag = 0;
			for (x = 0;x < 900;x++) {
				if (RGB(55, 60, 100) == getpixel(x, y)) //根据坐标返回该坐标的颜色
				{
					flag = 1;
					break;
				}
			}
			if (flag) break;
		}
		printf("起点坐标为:%d,%d", x, y);

		COLORREF bk = getpixel(10, 10);//获取背景颜色
		int dx, dy;//表示人物终点坐标
		for (dy = 0;dy < 900;dy++)
		{
			int flag = 0;
			for (dx = 0;dx < 900;dx++) {
				if (Similar(bk, getpixel(dx, dy))>25) //根据坐标返回该坐标的颜色
				{
					flag = 1;
					break;
				}
			}
			if (flag) break;
		}
		printf("起点坐标为:%d,%d", dx, dy);
		double d = sqrt(double((x - dx)*(x - dx) + (y - dy)*(y - dy)));
		double time = d * 1.18;
		char Str[128];
		sprintf(Str, "adb shell input swipe 200 200 195 195 %d", (int)time);//字符串拼接函数
		system(Str);//执行跳跃命令
	}
	system("pause");
	return 0;
}

double Similar(COLORREF color1, COLORREF color2)
{
  int R1=GetRValue(color1);
  int G1=GetGValue(color1);
  int B1=GetBValue(color1);
  int R2 = GetRValue(color2);
  int G2 = GetGValue(color2);
  int B2 = GetBValue(color2);
  return sqrt(double((R1 - R2)*(R1 - R2) + (G1 - G2)*(G1 - G2) + (B1 - B2)*(B1 - B2)));

}
posted @ 2020-10-15 12:53  66如风  阅读(102)  评论(0)    收藏  举报