JPG转化为CHAR数组

BOOL JPG2Bin(CString photoPath)
{
    
char szStr[256= {0};
    wcstombs(szStr, photoPath, 
256);
    
const char *strPath = szStr;
    
if(!strPath)
    {
        
return FALSE;
    }

    FILE 
*fp = fopen(strPath, "r+");
    
if(!fp)
    {
        
return FALSE;
    }

    fseek(fp, 
0L, SEEK_END);
    
int iFileSize = ftell(fp) * sizeof(char);
    
char *strTemp = new char[iFileSize + 1];

    fseek(fp, 
0L, SEEK_SET);
    
const int BLOCK = 512;
    
char fbuf[BLOCK]={0};
    
char *= strTemp;

    
int re = 0;
    
int index = 0;
    
do
    {
        
//p += index;
        re = fread(p + index,sizeof(char),BLOCK,fp);
        index 
+= re;
    } 
while (re > 0);
    
*(p + index) = '\0';

    
if (fp)
        fclose(fp);
    
return TRUE;
}
//要注意strTemp的释放

posted on 2012-02-24 15:15 @John 阅读(483) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2012年2月>
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910

导航

统计

常用链接

留言簿

随笔档案

搜索

最新评论