qq头像变灰是怎么做的? 有没比较简便的方法能实现呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不像是换了图片吧? 因为我在qq的表情目录下找不到灰色的头像而且QQ是可以自定义表情的,如果每个表情都给它变灰好像挺麻烦的?要把彩色图像保存成灰度有什么办法啊? 可能我表达错了,我不是想问头像切换的问题,我是想问一张图片怎么把它变灰我想QQ应该是存了两张图像,一张彩色的,一张灰度的,灰度是从彩色的生成的我试过用loadimage,指定以黑白模式装载,但发现效果很差 http://www.vckbase.com/document/viewdoc/?id=1793看看这个吧,你应该明白了 看了 9 楼给的方法,天啦,还用这么麻烦?//这是本人写的一个转换算法。效果好,但运行时间稍长HBITMAP BitmapColorToGray(CDC* pDC,HBITMAP hBitmap){ BITMAP bmpInfo; ::GetObject(hBitmap,sizeof(BITMAP),&bmpInfo); if(pDC) { CDC memDC; if( !memDC.CreateCompatibleDC(pDC) ) { return NULL; } HBITMAP oldBitmap = (HBITMAP)memDC.SelectObject(hBitmap); DWORD r,g,b; for (int H =0; H <= bmpInfo.bmHeight; H++) { for(int W = 0; W <= bmpInfo.bmWidth; W ++) { r = GetRValue(memDC.GetPixel(W,H)); g = GetGValue(memDC.GetPixel(W,H)); b = GetBValue(memDC.GetPixel(W,H)); r = (r * 3 + g * 6 + g) / 10; g = r; b = g; memDC.SetPixel(CPoint(W,H),RGB(r,g,b)); } } hBitmap = (HBITMAP)memDC.SelectObject(oldBitmap); memDC.DeleteDC(); } return hBitmap; }微软都做好了的,GDI+绘制代码: Graphics graphics(hdc); Image myImage(L"Image.jpg"); RectF source(0.0f, 0.0f, 330.0f, 300.0f); RectF destination(20.0f, 20.0f, 330.0f, 300.0f); DrawImage(graphics, &myImage, destination, source, UnitPixel, NULL); // 绘制原始图像 RectF destination2(420.0f, 20.0f, 330.0f, 300.0f);#define GRAY 32/256.0f /* gray/full, 0 - 256 : black to white, 16 - 64 is recommended */#define GRAY 0.125f /* 0.000 - 1.000 : black to white, 0.062 - 0.250 is recommended */#define FULL 1.000f#define ZERO 0.000f // 自由转换 ColorMatrix matrix = { GRAY, GRAY, GRAY, FULL, ZERO, GRAY, GRAY, GRAY, FULL, ZERO, GRAY, GRAY, GRAY, FULL, ZERO, GRAY, GRAY, GRAY, FULL, ZERO, ZERO, ZERO, ZERO, ZERO, FULL, }; ImageAttributes attributes; attributes.SetColorMatrix(&matrix); DrawImage(graphics, &myImage, destination2, source, UnitPixel, &attributes); // 绘制转换图像DrawImage 是自定义函数void DrawImage(Graphics& graphics, Image* image, RectF& destination, RectF& source, Unit unit, ImageAttributes* attributes){ graphics.DrawImage(image, destination, source.X, source.Y, source.Width, source.Height, unit, attributes);} 55555~~~c++的哦~~怎么改成js啊?????? 一个绝美的妹妹,希望大家来鉴定!绝无色情! 有2个地方置顶链接【无效】. 请问关于鼠标形状改变的大难题? 这类错误怎么解决? 如何设计这样一个对话框,中间切掉一个矩形,像一口井?谢谢; 关于删除注册表中的键的问题??? 如何按扇区读取DVD数据?在线等待 为什么我的msdn开始的时候会跳出一个对话框 请问如何在CMainFrame类中访问CDocument数据 为什么t.264的dshow的运行也不顺利 sockaddr_storage结构在什么头文件里定义? VC中怎么使用Chart FX 控件??
看看这个吧,你应该明白了
HBITMAP BitmapColorToGray(CDC* pDC,HBITMAP hBitmap)
{
BITMAP bmpInfo; ::GetObject(hBitmap,sizeof(BITMAP),&bmpInfo); if(pDC)
{
CDC memDC; if( !memDC.CreateCompatibleDC(pDC) )
{
return NULL;
} HBITMAP oldBitmap = (HBITMAP)memDC.SelectObject(hBitmap); DWORD r,g,b; for (int H =0; H <= bmpInfo.bmHeight; H++)
{
for(int W = 0; W <= bmpInfo.bmWidth; W ++)
{
r = GetRValue(memDC.GetPixel(W,H));
g = GetGValue(memDC.GetPixel(W,H));
b = GetBValue(memDC.GetPixel(W,H));
r = (r * 3 + g * 6 + g) / 10;
g = r;
b = g;
memDC.SetPixel(CPoint(W,H),RGB(r,g,b));
}
} hBitmap = (HBITMAP)memDC.SelectObject(oldBitmap); memDC.DeleteDC();
} return hBitmap;
}微软都做好了的,GDI+绘制代码: Graphics graphics(hdc);
Image myImage(L"Image.jpg");
RectF source(0.0f, 0.0f, 330.0f, 300.0f);
RectF destination(20.0f, 20.0f, 330.0f, 300.0f); DrawImage(graphics, &myImage, destination, source, UnitPixel, NULL); // 绘制原始图像
RectF destination2(420.0f, 20.0f, 330.0f, 300.0f);#define GRAY 32/256.0f /* gray/full, 0 - 256 : black to white, 16 - 64 is recommended */
#define GRAY 0.125f /* 0.000 - 1.000 : black to white, 0.062 - 0.250 is recommended */
#define FULL 1.000f
#define ZERO 0.000f // 自由转换
ColorMatrix matrix = {
GRAY, GRAY, GRAY, FULL, ZERO,
GRAY, GRAY, GRAY, FULL, ZERO,
GRAY, GRAY, GRAY, FULL, ZERO,
GRAY, GRAY, GRAY, FULL, ZERO,
ZERO, ZERO, ZERO, ZERO, FULL,
}; ImageAttributes attributes;
attributes.SetColorMatrix(&matrix);
DrawImage(graphics, &myImage, destination2, source, UnitPixel, &attributes); // 绘制转换图像DrawImage 是自定义函数void DrawImage(Graphics& graphics, Image* image, RectF& destination, RectF& source, Unit unit, ImageAttributes* attributes)
{
graphics.DrawImage(image, destination, source.X, source.Y, source.Width, source.Height, unit, attributes);
}