Mac读取Andriod屏幕截图

时间:2023-03-08 20:55:21
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[]; //存储每一行输出
size_t all=;
size_t readNum=fread(tmp,, sizeof(tmp)-, fstream); while (readNum!=)
{ if (tmp[readNum-] == 0xd)
{
tmp[readNum++] = fgetc(fstream);
} for (unsigned int i = ; i < readNum; ++i) {
if (tmp[i] == 0xd && tmp[i+] == 0xa ) {
tmp[i] = 0xa;
for (unsigned int j = i+; j < readNum - ; ++j)
tmp[j] = tmp[j+];
readNum--;
}
}
all=all+readNum; //写到文件
fwrite(tmp, , readNum, png);
//直接放到内存
[resultData appendBytes:tmp length:readNum]; readNum=fread(tmp,, sizeof(tmp)-, fstream);
} NSImage *img=[[NSImage alloc] initWithData:resultData]; NSLog(@"%f",img.size.width); return ;
}