• 2020.10.13 第十课 跳一跳小程序项目


    跳一跳程序

    1.获取手机的实时画面

    2.获取人物起点坐标

    3.获取人物终点坐标

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

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

    6.根据时长模拟人物按压手机屏幕

    1.adb工具截屏,按压手机屏幕

    adb shell screencap-p /sdcard/screen.png
    adb pull /sdcard/screen.png
     
    //                   按下的坐标  抬手坐标 按压时长
    adb shell input swipe 200 200  195 195  x
    system("xxx")放进去
        
        input swipe [duration(ms)] 
    向设备发送一个滑动指令,并且可以选择设置滑动时长。 
    //滑动操作  //从 100 100 经历300毫秒滑动到 200 200 
    adb shell input swipe 100 100 200 200  300 
      
    //长按操作
    adb shell input swipe 100 100 100 100  1000 //在 100 100 位置长按 1000毫秒
    

    2.修改图片格式

    //因为adb只能截取.png
    //easyx显示图片只能显示.jpg .bmp格式图片
    //格式转换
    
    #include<atlimage.h>
    CImage cimage;
    cimage.Load("screen.png");
    cimage.Save("screen.jpg");
    
    

    3.贴图三部曲

    1.定义2.加载3.显示
     //init=initialization(初始化)
     //graph=图表
     #include<graphics.h>
    initgraph(1080,1000,SHOWCONSOLE);//显示控制台
    IMAGE img;
    loadimage(&img,"screen.jpg")
    putimage(0,0,&img)//0,-600
     //电脑为1920*1080 手机截屏为1080*1920
    
    IMAGE img;
    SetWorkingImage(&screen);//设置绘图目标为screen
    getimage(&img, 0,700, 1080, 1000);
    /*getimage() 保存图像函数
    功能: 函数getimage()保存左上角与右下角所定义的屏幕上像素图形到指定的内存区域。*/
    SetWorkingImage(NULL);
    putimage(0, 0, &img);
    		
    

    4.起点坐标

    /*getpixel()函数功能:该函数检索指定坐标点的像素的RGB颜色值。
    COLORREF GetPixel(HDC hdc, int nXPos, int nYPos)
    hdc:设备环境句柄。
    nXPos:指定要检查的像素点的逻辑X轴坐标。
    nYPos:指定要检查的像素点的逻辑Y轴坐标。*/
    //RGB(红,绿,蓝)
    
    int x, y;
    
    		for (y = 1000; y >= 0; y--) {
    			int flag = 0;
    			for (x = 0; x <1080; x++) {
    				if (RGB(55, 60, 100) == getpixel(x, y)) {
    					flag = 1;
    					break;
    				}
    				//if(flag==1)break;
    			}
    
    			if (flag == 1)break;
    
    		}
    		printf("起点坐标为:(%d,%d)
    ", x, y);
    

    5.终点坐标

    COLORREF是一个32-bit整型数值,它代表了一种颜色。你可以使用RGB函数来初始化COLORREF,它的定义:
    COLORREF变量有两种赋值方法。
    第一种:
    COLORREF color = RGB(R,G,B);
    第二种:
    CColorDialog colorDialog;
    COLORREF color;
    if( colorDialog.DoModal() == IDOK )
    {
        color = colorDialog.GetColor();
    }
    第二种方法使用了MFC中的颜色对话框。
    如何从 COLORREF中取出RGB分量值?
    可以使用宏GetRValue、GetGValue、GetBValue。
    
    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)));
    }
    int main(){
    COLORREF bj = getpixel(30, 30);
    	
    		int dx, dy;
    		for (dy = 0; dy < 1000; dy++) {
    			int flag1 = 0;
    			for (dx = 0; dx < 1080; dx++) {
    				if (Similar(bj, (getpixel(dx, dy)) )>25) {
    					flag1 = 1;
    					break;
    				}
    
    			}
    			if (flag1 == 1)break;
    		}
    }
    		printf("终点坐标为(%d,%d)
    ", dx, dy);
    

    6.时间=距离/速度

    //距离  
    double d=sqrt(double( (x-dx)*(x-dx)+(y-dy)*(y-dy) ) );
    printf("距离=%f", d);
    
    //速度1.18-1.25
    double time=d/1.18
    

    7.按压时间

    char str[128];
    sprintf(str,"adb shell input swipe 200 200 195 195 %d",(int)time);
    system(str)
    
  • 相关阅读:
    hdu 1875 畅通project再续(kruskal算法计算最小生成树)
    Http post提交和get提交
    我的软考之路(五)——数据结构与算法(3)之图
    WPF 布局控件 之 DockPanel
    oracle存储结构
    马化腾最想做的事情是人工智能
    Android_Zip解压缩工具
    Unity的 Stats 窗体, Batched、SetPass、Draw Call 等
    尝试 “实验楼”在线教育平台
    POJ 3181 Dollar Dayz 01全然背包问题
  • 原文地址:https://www.cnblogs.com/heerha/p/13834554.html
Copyright © 2020-2023  润新知