欢迎来到天天文库
浏览记录
ID:13818907
大小:23.26 KB
页数:7页
时间:2018-07-24
《灰度图像淡入到彩色图像与彩色图像淡出到灰度图像》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、灰度图像淡入到彩色图像与彩色图像淡出到灰度图像voidFadeInColorORFadeOutGray(CDC*pDC,HANDLEhDIB,intxDest,intyDest,intnLoops,intnDelay,intnFlag){CPalettepal;CPalette*pOldPalette;PALETTEENTRYpAnimate[256];PALETTEENTRYpGray[256];PALETTEENTRYpOriginal[256];BITMAPINFO&bmInfo=*(LPBITMAPIN
2、FO)hDIB;¡¡intnColors=bmInfo.bmiHeader.biClrUsed?bmInfo.bmiHeader.biClrUsed:1<236?236:nReservedColors;intnWidth=bmInfo.bmiHeader.biWidth;intnHeight=bmInfo.bmiHeader.biHeight;LPVOIDlpDIBBits=(LPVOID)(bmIn
3、fo.bmiColors+nColors);if(pDC->GetDeviceCaps(RASTERCAPS)&RC_PALETTE&&nColors<=256){HPALETTEhPal=Create236Palette(hDIB);pal.Attach(hPal);//µÃµ½Î»Í¼µ÷É«°åpal.GetPaletteEntries(0,nReservedColors,(LPPALETTEENTRY)&pOriginal);for(inti=0;i4、½ÑÕÉ«¶ÔÓ¦»Ò¶ÈÖµintnGray=(pOriginal[i].peRed*299+pOriginal[i].peGreen*587+pOriginal[i].peBlue*114)/1000;pGray[i].peRed=nGray;pGray[i].peGreen=nGray;pGray[i].peBlue=nGray;pGray[i].peFlags=PC_RESERVED;}pOldPalette=pDC->SelectPalette(&pal,FALSE);pDC->RealizePale5、tte();CDCmemDC;memDC.CreateCompatibleDC(pDC);CBitmapbmp;bmp.CreateCompatibleBitmap(pDC,nWidth,nHeight);CBitmap*pOldBitmap=memDC.SelectObject(&bmp);CPalette*pOldMemPalette=memDC.SelectPalette(&pal,FALSE);memDC.RealizePalette();::SetDIBitsToDevice(memDC.m_hDC,6、0,0,nWidth,nHeight,0,0,0,nHeight,lpDIBBits,(LPBITMAPINFO)hDIB,DIB_RGB_COLORS);if(nFlag==1)//ÉèÖûҶȵ÷É«°åAnimatePalette(hPal,0,nColors,(LPPALETTEENTRY)&pGray);pDC->BitBlt(xDest,yDest,nWidth,nHeight,&memDC,0,0,SRCCOPY);//ÉèÖö¯Ì¬µ÷É«°å³õʼֵΪµ±Ç°µ÷É«°åpal.G7、etPaletteEntries(0,nColors,(LPPALETTEENTRY)&pAnimate);¡¡memDC.SelectPalette(pOldMemPalette,FALSE);memDC.SelectObject(pOldBitmap);//µÈëµ³öfor(i=1;i<=nLoops;i++){for(intj=0;j8、al[j].peRed)*i)/nLoops;pAnimate[j].peGreen=pGray[j].peGreen-((pGray[j].peGreen-pOriginal[j].peGreen)*i)/nLoops;pAnimate[j].peBlue=pGray[j].peBlue-((pGray[j].peBlue-pOriginal[j].peBlue)*i)/nLoops
4、½ÑÕÉ«¶ÔÓ¦»Ò¶ÈÖµintnGray=(pOriginal[i].peRed*299+pOriginal[i].peGreen*587+pOriginal[i].peBlue*114)/1000;pGray[i].peRed=nGray;pGray[i].peGreen=nGray;pGray[i].peBlue=nGray;pGray[i].peFlags=PC_RESERVED;}pOldPalette=pDC->SelectPalette(&pal,FALSE);pDC->RealizePale
5、tte();CDCmemDC;memDC.CreateCompatibleDC(pDC);CBitmapbmp;bmp.CreateCompatibleBitmap(pDC,nWidth,nHeight);CBitmap*pOldBitmap=memDC.SelectObject(&bmp);CPalette*pOldMemPalette=memDC.SelectPalette(&pal,FALSE);memDC.RealizePalette();::SetDIBitsToDevice(memDC.m_hDC,
6、0,0,nWidth,nHeight,0,0,0,nHeight,lpDIBBits,(LPBITMAPINFO)hDIB,DIB_RGB_COLORS);if(nFlag==1)//ÉèÖûҶȵ÷É«°åAnimatePalette(hPal,0,nColors,(LPPALETTEENTRY)&pGray);pDC->BitBlt(xDest,yDest,nWidth,nHeight,&memDC,0,0,SRCCOPY);//ÉèÖö¯Ì¬µ÷É«°å³õʼֵΪµ±Ç°µ÷É«°åpal.G
7、etPaletteEntries(0,nColors,(LPPALETTEENTRY)&pAnimate);¡¡memDC.SelectPalette(pOldMemPalette,FALSE);memDC.SelectObject(pOldBitmap);//µÈëµ³öfor(i=1;i<=nLoops;i++){for(intj=0;j8、al[j].peRed)*i)/nLoops;pAnimate[j].peGreen=pGray[j].peGreen-((pGray[j].peGreen-pOriginal[j].peGreen)*i)/nLoops;pAnimate[j].peBlue=pGray[j].peBlue-((pGray[j].peBlue-pOriginal[j].peBlue)*i)/nLoops
8、al[j].peRed)*i)/nLoops;pAnimate[j].peGreen=pGray[j].peGreen-((pGray[j].peGreen-pOriginal[j].peGreen)*i)/nLoops;pAnimate[j].peBlue=pGray[j].peBlue-((pGray[j].peBlue-pOriginal[j].peBlue)*i)/nLoops
此文档下载收益归作者所有