关于unicode字符集和多字节字符集

无法支持的类型 2016-08-17 09:56:24
我以前用多字节字符集,但是最近在调用第三方dll是,错误代码是乱码。我百度后知道是多字节字符集好像不大支持utf-8的编码方式。所以改为unicode字符集。但是有个问题,

for(int i=0;i<10;i++){
char begin[10]="E:\\Image\\";
char end[10]=".png";
CImage img;
CStatic *idc_photo=(CStatic*)GetDlgItem(IDC_PIC1+i);
char num[10];
itoa(i+1,num,10);//十进制
char result[100];
memset(result,0,100);
strcat(result,begin);
strcat(result,num);
strcat(result,end);
img.Load(result);
if(img.IsNull())
{
return ;
}
if (img.GetBPP() == 32) //确认该图像包含Alpha通道
{ int w; int h; for (w = 0; w < img.GetWidth(); w++)
{ for (h = 0; h < img.GetHeight(); h++)
{
byte *pByte = (byte *)img.GetPixelAddress(w, h);
pByte[0] = pByte[0] * pByte[3] / 255;
pByte[1] = pByte[1] * pByte[3] / 255;
pByte[2] = pByte[2] * pByte[3] / 255;
}
}
}
CRect m_picRect;
idc_photo->GetClientRect(&m_picRect);
CDC* cd = idc_photo->GetWindowDC();
int width = img.GetWidth();
int height = img.GetHeight();
SetStretchBltMode(cd->m_hDC, HALFTONE);
img.Draw(cd->m_hDC, m_picRect);
ReleaseDC(cd);
}

img.Load(result);报错,说是没有与CImage::Load参数列表匹配的实例。
我觉得应该是result这个字符串的问题。我想问一下,我应该怎么更改?
或者我能用多字节字符集吗?
...全文
215 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
zgl7903 2016-08-18
  • 打赏
  • 举报
回复
CImage HRESULT Load( LPCTSTR pszFileName ) throw( ); 用 TCHAR LPTSTR LPCTSTR 可适应不同的编译环境 _tfopen 可适应
  • 打赏
  • 举报
回复

int ImgData2BMP(CString path, BYTE *plmgData,int width,int height)
{
	
   	FILE               *fp = NULL;

	// 创建文件
	fp = fopen(path, "wb");
	//fopen_s(&fp,path, "wb" );
	if(fp == NULL)
	{
		return 1;
	}

    fwrite(plmgData,1, width*height+1078, fp);

	fclose(fp);	
	
	return 0;
}
这里面的fopen不能用了,要用_wfopen;但是_wfopen(path,“wb”)不对。请教大神,应该怎么改。。。。
赵4老师 2016-08-17
  • 打赏
  • 举报
回复
for(int i=0;i<10;i++) {
    TCHAR begin[10]=_T("E:\\Image\\");
    TCHAR end[10]=_T(".png");
    CImage img;
    CStatic *idc_photo=(CStatic*)GetDlgItem(IDC_PIC1+i);
	TCHAR	num[10];
    _itot(i+1,num,10);//十进制
	TCHAR	result[100];
    memset(result,0,100*sizeof(TCHAR));
    _tcscat(result,begin);
    _tcscat(result,num);
    _tcscat(result,end);
    img.Load(result);
    if(img.IsNull()) {
        return ;
    }
    if (img.GetBPP() == 32) //确认该图像包含Alpha通道
        { int w; int h; for (w = 0; w < img.GetWidth(); w++) {
			for	(h = 0;	h	< img.GetHeight(); h++)	{
                byte *pByte = (byte *)img.GetPixelAddress(w, h);
                pByte[0] = pByte[0] * pByte[3] / 255;
                pByte[1] = pByte[1] * pByte[3] / 255;
                pByte[2] = pByte[2] * pByte[3] / 255;
            }
        }
    }
    CRect m_picRect;
    idc_photo->GetClientRect(&m_picRect);
    CDC* cd = idc_photo->GetWindowDC();
    int width = img.GetWidth();
    int height = img.GetHeight();
    SetStretchBltMode(cd->m_hDC, HALFTONE);
    img.Draw(cd->m_hDC, m_picRect);
    ReleaseDC(cd);
}

许文君 2016-08-17
  • 打赏
  • 举报
回复
http://blog.csdn.net/leitianjun/article/details/5605410/ 各编码方式互转就行了,不需要你工程修改字符集
  • 打赏
  • 举报
回复
得先搞清楚,第三方的错误信息的编码是什么。
  • 打赏
  • 举报
回复
引用 4 楼 wangkuo106 的回复:
[quote=引用 1 楼 akirya 的回复:] 得先搞清楚,第三方的错误信息的编码是什么。
编码utf-8。。。这是编码吗[/quote] 是啊 操作系统还不直接支持显示UTF8,转成UNICODE就可以正常显示出来了
  • 打赏
  • 举报
回复
引用 1 楼 akirya 的回复:
得先搞清楚,第三方的错误信息的编码是什么。
编码utf-8。。。这是编码吗

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧