求位图转换源码:真彩图<->256色<->灰度图,推者有分

pinel 2001-12-11 05:09:41
...全文
221 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
dongfa 2001-12-12
  • 打赏
  • 举报
回复
好啊
pinel 2001-12-12
  • 打赏
  • 举报
回复
dongfa(阿东) :看了你的主页,原来也在上海,有机会多交流
dongfa 2001-12-12
  • 打赏
  • 举报
回复
还有谁要,请到我的http://dongfa.yeah.net,有偷窥者的源程序,里面有我开发的PL lib
dongfa 2001-12-12
  • 打赏
  • 举报
回复
谢谢,这个软件我早就发布了,源程序也早就开发了。其中还有一些BUG,现在也没有时间解决了。
pinel 2001-12-12
  • 打赏
  • 举报
回复
dongfa(阿东) :您太牛了,这个软件也正是我想要的,多谢多谢!!!
xtky_limi 2001-12-12
  • 打赏
  • 举报
回复
旁听
dongfa 2001-12-12
  • 打赏
  • 举报
回复
已经给你发了,这是我在开发偷窥者时开发的一套库.请参考.
pinel 2001-12-12
  • 打赏
  • 举报
回复
: dongfa(阿东) 快来 加分拉
cafecai 2001-12-11
  • 打赏
  • 举报
回复
我推
pinel 2001-12-11
  • 打赏
  • 举报
回复
没人知道吗?
pinel 2001-12-11
  • 打赏
  • 举报
回复
急死啦!谁帮我???
tuggfox 2001-12-11
  • 打赏
  • 举报
回复
关注
tuggfox 2001-12-11
  • 打赏
  • 举报
回复
关注
tuggfox 2001-12-11
  • 打赏
  • 举报
回复
关注
snlee 2001-12-11
  • 打赏
  • 举报
回复
study
pinel 2001-12-11
  • 打赏
  • 举报
回复
sorry ,请提供 PL_PaletteSize()函数或源程序: pinel@263.net ,多谢!
pinel 2001-12-11
  • 打赏
  • 举报
回复
谢谢!,我试试
dongfa 2001-12-11
  • 打赏
  • 举报
回复
nBits是你想转换的颜色位数,
HDIB WINAPI PL_BmpToDIB(HBITMAP hBitmap, HPALETTE hPal, int nBits)
{
BITMAP bm;
BITMAPINFOHEADER bi;
LPBITMAPINFOHEADER lpbi;
DWORD dwLen;
HANDLE hDIB, h;
HDC hDC;
WORD biBits;

if(!hBitmap)
return NULL;

if(!GetObject(hBitmap, sizeof(bm), (LPSTR)&bm))
return NULL;
if (hPal == NULL)
hPal = (HPALETTE) GetStockObject(DEFAULT_PALETTE);
biBits = bm.bmPlanes * bm.bmBitsPixel;
if (biBits <= 1)
biBits = 1;
else if (biBits <= 4)
biBits = 4;
else if (biBits <= 8)
biBits = 8;
else
biBits = 24;
if(nBits != -1)
{
if(nBits == 1 || nBits == 4 || nBits == 8 || nBits == 24)
{
biBits = nBits;
}
}
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = bm.bmWidth;
bi.biHeight = bm.bmHeight;
bi.biPlanes = 1;
bi.biBitCount = biBits;
bi.biCompression = BI_RGB;
bi.biSizeImage = 0;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
dwLen = bi.biSize + PL_PaletteSize((LPBYTE)&bi);

hDC = GetDC(NULL);
hPal = SelectPalette(hDC, hPal, FALSE);
RealizePalette(hDC);
hDIB = GlobalAlloc(GHND, dwLen);
if (!hDIB)
{
SelectPalette(hDC, hPal, TRUE);
RealizePalette(hDC);
ReleaseDC(NULL, hDC);
return NULL;
}
lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIB);
*lpbi = bi;
GetDIBits(hDC, hBitmap, 0, (UINT)bi.biHeight, NULL, (LPBITMAPINFO)lpbi,
DIB_RGB_COLORS);
bi = *lpbi;
GlobalUnlock(hDIB);

if (bi.biSizeImage == 0)
bi.biSizeImage = WIDTHBYTES((DWORD)bm.bmWidth * biBits) * bm.bmHeight;
dwLen = bi.biSize + PL_PaletteSize((LPBYTE)&bi) + bi.biSizeImage;

if (h = GlobalReAlloc(hDIB, dwLen, 0))
hDIB = h;
else
{
GlobalFree(hDIB);
hDIB = NULL;
SelectPalette(hDC, hPal, TRUE);
RealizePalette(hDC);
ReleaseDC(NULL, hDC);
return NULL;
}
lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDIB);
if (GetDIBits(hDC, hBitmap, 0, (UINT)bi.biHeight, (LPSTR)lpbi +
(WORD)lpbi->biSize + PL_PaletteSize((LPBYTE)lpbi), (LPBITMAPINFO)lpbi,
DIB_RGB_COLORS) == 0)
{
GlobalUnlock(hDIB);
hDIB = NULL;
SelectPalette(hDC, hPal, TRUE);
RealizePalette(hDC);
ReleaseDC(NULL, hDC);
return NULL;
}

bi = *lpbi;
GlobalUnlock(hDIB);
SelectPalette(hDC, hPal, TRUE);
RealizePalette(hDC);
ReleaseDC(NULL, hDC);

return (HDIB) hDIB;
}

转换灰度,可换算法:
double r = (double)(rgb[nIndex].rgbRed);
double g = (double)(rgb[nIndex].rgbGreen);
double b = (double)(rgb[nIndex].rgbBlue);
BYTE c = (BYTE)(r*0.29900 + g*0.58700 + b*0.11400);
pinel 2001-12-11
  • 打赏
  • 举报
回复
高手不多阿

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧