16,154
社区成员
发帖
与我相关
我的任务
分享
FILE * f = fopen("d:/1.png","rb");
if(f==NULL){
printf("image open error!\n");
exit(-1);
}else{
printf("image open success!!!\n");
}
fseek(f,0,SEEK_END);
long length = ftell(f);
// printf("file length : %d\n",length);
char * p = new char[length];
fgets(p,length,f);
uchar * q = new uchar[length];
memcpy(q,p,length);
/* QImage image(q,768,576,3,QImage::Format_ARGB6666_Premultiplied);*/
[/quote]
首先,fgets 用在这儿不对。
其次,p 分配的大小不对。
再次,q 有必要重新分配内容再拷贝么?为什么不直接用一个p或q[/quote]fgets确实不对,换成fread就好,q的存在主要是测试memcpy拷贝的时间,没有其他的意思。FILE * f = fopen("d:/1.png","rb");
if(f==NULL){
printf("image open error!\n");
exit(-1);
}else{
printf("image open success!!!\n");
}
fseek(f,0,SEEK_END);
long length = ftell(f);
// printf("file length : %d\n",length);
char * p = new char[length];
fgets(p,length,f);
uchar * q = new uchar[length];
memcpy(q,p,length);
/* QImage image(q,768,576,3,QImage::Format_ARGB6666_Premultiplied);*/
[/quote]
首先,fgets 用在这儿不对。
其次,p 分配的大小不对。
再次,q 有必要重新分配内容再拷贝么?为什么不直接用一个p或qFILE * f = fopen("d:/1.png","rb");
if(f==NULL){
printf("image open error!\n");
exit(-1);
}else{
printf("image open success!!!\n");
}
fseek(f,0,SEEK_END);
long length = ftell(f);
// printf("file length : %d\n",length);
char * p = new char[length];
fgets(p,length,f);
uchar * q = new uchar[length];
memcpy(q,p,length);
/* QImage image(q,768,576,3,QImage::Format_ARGB6666_Premultiplied);*/