小弟写的程序有点问题,想请教各位大虾。
解决方案 »
- 请教AES-CBC中的填充数据问题
- 打算换公司,如何将vc写的客户端软件做成控件,供客户浏览器使用?
- 如何保证一个dll在内存中只有一个实例?
- 在线求教:给对话框加上背景图!
- 高手帮我调试电子白板程序?
- 关于ping的计时问题
- 单列表显示指定目录下的 各个文件名的函数?
- 100分求:yuvViewer源代码。只要能播放yuv(4:2:x)文件就可以
- 怎样才能向CListCtrl的子项中加入图像?
- vc# 建立控制台应用程序,如何调用CommonOpenFileDialog,打开通用对话框?
- 请教各位:自己用VC最低层的SOCKET程序,编译通过了,但是链接出错,为什么?怎么弄?
- 如何在右键弹出的菜单中打勾????
这个是转换函数.
只要你能够正确显示BMP位图,转换是很简单的.
1.对图片中的所有颜色做亮度和饱和度分析排序,按人眼的敏感度将前256种放到调色版。
2.扫描所有像素点的值,把它们的24BIT或32BIT颜色值换成8BIT的调色版索引。(如果调色版中不存在着种颜色,就找最相近的替换)。
if (!m_image.IsIndexed()) { // the image does not use an indexed palette, so we will change each pixel to B&W (slow)
COLORREF pixel;
int maxY = m_image.GetHeight(), maxX = m_image.GetWidth();
byte r,g,b,avg;
for (int x=0; x<maxX; x++) {
for (int y=0; y<maxY; y++) {
pixel = m_image.GetPixel(x,y);
r = GetRValue(pixel);
g = GetGValue(pixel);
b = GetBValue(pixel);
avg = ((r + g + b)/3);
m_image.SetPixelRGB(x,y,avg,avg,avg);
}
} } else { // the image uses an indexed palette, so we will just change the palette table entries to
// their B&W equivalents
int MaxColors = m_image.GetMaxColorTableEntries();
RGBQUAD* ColorTable;
ColorTable = new RGBQUAD[MaxColors]; m_image.GetColorTable(0,MaxColors,ColorTable);
for (int i=0; i<MaxColors; i++)
{
int avg = (ColorTable[i].rgbBlue + ColorTable[i].rgbGreen + ColorTable[i].rgbRed)/3;
ColorTable[i].rgbBlue = (BYTE)avg;
ColorTable[i].rgbGreen = (BYTE)avg;
ColorTable[i].rgbRed = (BYTE)avg;
}
m_image.SetColorTable(0,MaxColors,ColorTable);//=============================================================================
{
// TODO: Add your command handler code here
//加载位图文件
BITMAPFILEHEADER bf;
BITMAPINFO *binfoin,*binfoout;
//创建两个信息头
CFile file;
if(!file.Open(str,CFile::modeRead,NULL)) return; binfoin=(BITMAPINFO *)malloc(sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)+10);
binfoout=(BITMAPINFO *)malloc(sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)+10);
file.Read(&bf,sizeof(BITMAPFILEHEADER));
file.Read(binfoin,sizeof(BITMAPINFOHEADER));
int nline=((binfoin->bmiHeader.biWidth* binfoin->bmiHeader.biBitCount+31)/8) /4*4;
int nsize=nline*(binfoin->bmiHeader.biHeight);
int nline8=((binfoin->bmiHeader.biWidth* 8+31)/8) /4*4;
int nsize8=nline8*(binfoin->bmiHeader.biHeight);
unsigned char *pdata,*pdata8;
//为源数据开辟缓冲区
pdata=(unsigned char *)malloc(nsize+nline+10);//注意这里必须申请一块大一点的空间,不然会益处
//为目标数据开辟缓冲区
pdata8=(unsigned char *)malloc(nsize8+10);
file.Read(pdata,nsize);
file.Close();
//调用dll库中的函数 HINSTANCE hinstLib;
MYPROC ProcAdd;
hinstLib = LoadLibrary("demcolordll1");
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "RGB2256HiQuality");
if(ProcAdd !=NULL)
{
ProcAdd(binfoin,pdata,binfoout,pdata8);
FreeLibrary(hinstLib);
//将得到的数据写进文件中
if(file.Open("temp.bmp",CFile::modeCreate|CFile::modeWrite,NULL))
{
bf.bfOffBits=bf.bfOffBits+1024;
bf.bfSize=bf.bfOffBits+nsize8;
file.Write(&bf,sizeof(BITMAPFILEHEADER));
file.Write(binfoout,sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*256);
file.Write(pdata8,nsize8);
file.Close();
}
}
}
free(binfoin);
free(binfoout);
free(pdata);
free(pdata8);
HBITMAP hBitmap=(HBITMAP)LoadImage(NULL,"temp.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION);
// CDC tempDC;
if(hBitmap==NULL) return;
bitmap.DeleteObject();
bitmap.Attach(hBitmap);
bitmap.GetObject(sizeof(BITMAP),&bm);
bShow=true;
Invalidate();
}
小土的做法正确。灰度图与RGB关系为:Lightness = ( R + G + B ) / 3;
我是用读取位数据,在变化为灰度位数据,通过屏幕打点的方式显示。
我现在想通过直接对位图本身进行处理,包括8位和24位的,在思路上还很模糊
你能说说你是怎么做的吗?
[email protected]
QQ:117220198
正确的公式为
*Lightness =(int)(.299 * (double)(*pRed) + .587 * (double)(*pGrn) + .114 * (double)(*pBlu));
多谢http://www.5ivb.net/club/dispbbs.asp?boardID=1&ID=22563