2012年2月24日

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 @ 2012-02-24 15:15 @John 阅读(483) | 评论 (0)编辑 收藏

仅列出标题  
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

常用链接

留言簿

随笔档案

搜索

最新评论