MFC-相关总结

1.获取鼠标点击颜色

CPoint pt;
CString mycolor;
GetCursorPos(&pt);//得到点位置

HDC hDC = ::GetDC(NULL);//创建绘制空的DC
COLORREF clr = ::GetPixel(hDC,pt.x, pt.y );//pt.x, pt.y
CString ClrText;

ClrText.Format("红色值:%d;",GetRValue(clr));
mycolor="当前位置颜色值分别是=>"+ClrText;

ClrText.Format("绿色值%d;",GetGValue(clr));
mycolor=mycolor+ClrText;

ClrText.Format("蓝色值%d.\n",GetBValue(clr));
mycolor=mycolor+ClrText;

printf(mycolor);

::ReleaseDC(NULL, hDC);

2 按像素处理CImage,下面是进行了一个灰度处理

CImage *image = new CImage();
image->Load("light_color.png");
image->SetTransparentColor(RGB(255, 252 , 253));

int maxY = image->GetHeight(), maxX = image->GetWidth();
byte r,g,b,avg;
byte* pRealData;
pRealData = (byte*)image->GetBits();

int pit = image->GetPitch();
int bitCount = image->GetBPP()/8;

for (int y=0; y<maxY; y++) {
for (int x=0; x<maxX; x++) {
int r = (int)((pRealData + pity + xbitCount + 2));
int g = (int)(
(pRealData + pity + xbitCount + 1));
int b = (int)((pRealData + pity + x*bitCount + 0));

if (!isShowColor(r, g, b))
{
(pRealData + pity + xbitCount) = 253;
(pRealData + pity + x
bitCount +1) = 252;
(pRealData + pity + x*bitCount +2) = 255;
}
//如果是8位灰度图像,直接读取一个BYTE位为灰度值

//如果是24位RGB图像,则依次读取pixAddr,pixAddr+1,pixAddr+2为B、G、R分量值
}
}

TransparentPNG(image);

CImage *tmp = test;
test = image;
if(tmp != NULL) delete tmp;
}

3 特效制作-图片掉下效果

定时调用这个部分

float addDegree = 35.0;
float addTmp = 1.05;

if(degree < 400)
{
degree += 400;
//icon_china.Draw(m_cacheDC, china_x, (china_y + china_height) * degree / 500 - china_y, china_width, china_height);
}
else if (degree < 600)
{
degree += 50;
int x = (degree - 400) / 200.0 * china_width * addTmp / 2.0;
int y = (degree - 400) / 200.0 * china_height * addTmp;
icon_china.Draw(m_cacheDC, china_x + china_width / 2 - x, china_y + china_height - y, x * 2, y);
}
else if(degree < 700)
{
degree += addDegree;
int x = ((700 - degree) / 100.0 * (addTmp - 1) + 1) * china_width * addTmp / 2.0;
int y = ((700 - degree) / 100.0 * (addTmp - 1) + 1) * china_height * addTmp;
icon_china.Draw(m_cacheDC, china_x + china_width / 2 - x, china_y + china_height - y, x * 2, y);
}
else
{
icon_china.Draw(m_cacheDC, china_x, china_y, china_width, china_height);
}

  1. 特效制作-图片弹出效果

`

定时调用这个部分
float addDegree = 35.0;
float addTmp = 1.05;
if(degree < 400)
{
degree += 400;
//icon_china.Draw(m_cacheDC, china_x, (china_y + china_height) * degree / 500 - china_y, china_width, china_height);
}
else if (degree < 600)
{
degree += 50;
int x = (degree - 400) / 200.0 * china_width * addTmp / 2.0;
int y = (degree - 400) / 200.0 * china_height * addTmp;
icon_china.Draw(m_cacheDC, china_x + china_width / 2 - x, china_y + china_height - y, x * 2, y);
}
else if(degree < 700)
{
degree += addDegree;
int x = ((700 - degree) / 100.0 * (addTmp - 1) + 1) * china_width * addTmp / 2.0;
int y = ((700 - degree) / 100.0 * (addTmp - 1) + 1) * china_height * addTmp;
icon_china.Draw(m_cacheDC, china_x + china_width / 2 - x, china_y + china_height - y, x * 2, y);
}
else
{
icon_china.Draw(m_cacheDC, china_x, china_y, china_width, china_height);
}

posted @ 2015-05-02 13:36  Nyle  阅读(161)  评论(0)    收藏  举报