WM图片变灰处理
来源:互联网 发布:js代码封装 编辑:程序博客网 时间:2024/04/29 01:30
因为在Windows mobile 上没有
GetBitmapBits和SetBitmapBits
所以只能用CreateDIBSection函数。
查看了些资料,入下:
///////////////////////////////////////////////////////////////////////////////////////////
wm
转载自:http://www.qqgb.com/Program/VC/VCJM/Program_137059.html
// 核心函数,将屏幕变暗
HBITMAP CMyFade::FadeBitmap(HBITMAP hBmp, double dfTrans)
{
HBITMAP hRetBmp = NULL;
if (hBmp)
{
HDC hBufferDC = CreateCompatibleDC(NULL);
HGDIOBJ hPrevBufObject = SelectObject(hBufferDC, hBmp);
HDC hDirectDC = CreateCompatibleDC(NULL);// DC for working
if (hDirectDC)
{
BITMAP bm;
GetObject(hBmp, sizeof(bm), &bm);
BITMAPINFO bmInfo;
ZeroMemory(&bmInfo,sizeof(bmInfo));
bmInfo.bmiHeader.biSize= sizeof(BITMAPINFOHEADER);
bmInfo.bmiHeader.biWidth= bm.bmWidth;
bmInfo.bmiHeader.biHeight= bm.bmHeight;
bmInfo.bmiHeader.biPlanes= 1;
bmInfo.bmiHeader.biBitCount= 32;
UINT* ptPixels;
HBITMAP hDirectBitmap = CreateDIBSection(hDirectDC,
(BITMAPINFO*)&bmInfo,
DIB_RGB_COLORS,(void**)&ptPixels, NULL, 0);
if (hDirectBitmap)
{
// 将hDirectBitmap放入hDirectDC中处理
HGDIOBJ hPrevBufDirObject = SelectObject(hDirectDC, hDirectBitmap);
// 当前将原hBmp即屏幕的所有像素写入到hDirectDC
// 即需要对像素灰度处理的DC中
BitBlt(hDirectDC,0,0,bm.bmWidth,bm.bmHeight,hBufferDC,0,0,SRCCOPY);
int iAlpha = (int)(255.0 * dfTrans / 100.0);
int nSize = bm.bmWidth * bm.bmHeight;
for (int i=0; i<nSize; i++)
{
// 0.212671 * R + 0.715160 * G + 0.072169 * B
int iSrcR = (ptPixels[i]) & 0x00ff0000 >> 16;
int iSrcG = ptPixels[i] & 0x0000ff00 >> 8;
int iSrcB = ptPixels[i] & 0x000000ff;
int iGrey = (iSrcR * 54 + iSrcG * 182 + iSrcB * 19) >> 8;
COLORREF Col =iGrey ; //RGB(iGrey, iGrey, iGrey) ;
ptPixels[i] = RGB(
(GetBValue( Col ) * iAlpha + iSrcB * (255 - iAlpha)) >> 8,
(GetGValue( Col ) * iAlpha + iSrcG * (255 - iAlpha)) >> 8,
(GetRValue( Col ) * iAlpha + iSrcR * (255 - iAlpha)) >> 8 );
}
SelectObject(hDirectDC,hPrevBufDirObject);
hRetBmp = hDirectBitmap;
}
DeleteDC(hDirectDC);
}
SelectObject(hBufferDC, hPrevBufObject);
DeleteDC(hBufferDC);
}
return hRetBmp;
}
/////////////////////////////////////////////////////////////////
vc
BITMAP bm;
GetObject(bitmap1, sizeof(BITMAP), &bm);
BYTE *pData = new BYTE[bm.bmWidthBytes * bm.bmHeight];
GetBitmapBits(bitmap1, bm.bmWidthBytes * bm.bmHeight, pData);
int bits = bm.bmWidthBytes / bm.bmWidth;
for (int i = m_Shape.lMinY; i < m_Shape.lMaxY; i++)
{
for (int k = m_Shape.lMinX * bits; k < m_Shape.lMaxX * bits; k += bits)
{
BYTE Gray = pData[i * bm.bmWidthBytes + k] * 0.3 + pData[i * bm.bmWidthBytes + k + 1] * 0.59 + pData[i * bm.bmWidthBytes + k + 2] * 0.11;
if (Gray + nGrade > 255)
{
Gray = 255;
}
else
{
if (Gray + nGrade < 0)
{
Gray = 0;
}
else
{
Gray += nGrade;
}
}
pData[i * bm.bmWidthBytes + k] = Gray;
pData[i * bm.bmWidthBytes + k + 1] = Gray;
pData[i * bm.bmWidthBytes + k + 2] = Gray;
}
}
SetBitmapBits(bitmap1, bm.bmWidthBytes * bm.bmHeight, pData);<
- WM图片变灰处理
- IOS 图片去色 变灰处理
- Swing图片变灰
- WPF 图片变灰
- css 图片变灰
- 图片变灰
- CSS使图片变灰
- cocos2d-x 图片变灰
- 图片变灰shader mark
- ngui 图片变灰Shader
- CSS快速让图片变灰,网站快速变灰
- 图片置灰处理
- 让页面图片文字整体变灰
- 用css3实现图片变灰
- AndEngine图片变灰效果实现
- cocos2d-x图片变灰或者变亮
- Unity图片变灰的方式
- cocos2dx 3.2 图片以及按钮变灰
- 笔试面试之二叉树的深度
- 进程通信--共享内存
- 黑莓上手机信息导出方法
- 如何得到黑莓手机的system uptime,也就是不间断运行时间
- 用InstallShield 进行 ASP 软件的打包和自动安装
- WM图片变灰处理
- Redhat 网页服务器架设
- C# Windows Api的一些方法 封装 以及 常用参数
- C# Windows Api的一些方法 封装 以及 常用参数
- 如何在黑莓屏幕上画表格
- Spring事务配置的五种方式
- 如果在BlackBerry上实现动态分页的效果
- 解决出现fatal error LNK1169: one or more multiply
- C#实现任务栏通知窗口