码迷,mamicode.com
首页 > 系统相关 > 详细

Mac读取Andriod屏幕截图

时间:2016-01-14 09:51:14      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:

int main(int argc, const char * argv[]) {
    // insert code here...
    
    
    string str3 = "/Users/Ethan/Downloads/aaa/platform-tools/adb shell screencap -p";
    NSMutableData *resultData=[[NSMutableData alloc] init];
    FILE * fstream = NULL;

    if(NULL==(fstream=popen(str3.c_str(),"r")))
    {
        fprintf(stderr,"execute command failed: %s",strerror(errno));
        return NULL;
    }
    
   FILE *png = fopen("/var/folders/_g/mmsygkld2sv2pl719654cscm0000gn/T/2.png", "w");

    char tmp[1024]; //存储每一行输出
    size_t all=0;
    size_t readNum=fread(tmp,1, sizeof(tmp)-1, fstream);

    while (readNum!=0)
    {
       
        if (tmp[readNum-1] == 0xd)
        {
            tmp[readNum++] = fgetc(fstream);
        }
        
      
        for (unsigned int i = 0; i < readNum; ++i) {
            if (tmp[i] == 0xd && tmp[i+1] == 0xa ) {
                tmp[i] = 0xa;
                for (unsigned int j = i+1; j < readNum - 1; ++j)
                    tmp[j] = tmp[j+1];
                readNum--;
            }
        }
         all=all+readNum;
        
        //写到文件
        fwrite(tmp, 1, readNum, png);
        //直接放到内存
        [resultData appendBytes:tmp length:readNum];
       
        readNum=fread(tmp,1, sizeof(tmp)-1, fstream);
    }
 
   
    NSImage *img=[[NSImage alloc] initWithData:resultData];
    
    NSLog(@"%f",img.size.width);

   
  
    return 0;
}

 

Mac读取Andriod屏幕截图

标签:

原文地址:http://www.cnblogs.com/bandy/p/5129146.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!