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;
}