3,245
社区成员
发帖
与我相关
我的任务
分享
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);
}
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”)不对。请教大神,应该怎么改。。。。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);
}