??1bit转8bit,用CreateDIBSection显示到DC上,为什么全黑? 有了阿?memcpy(&(m_lpbyteBi.bmiColors),&(m_lpBi->bmiColors),sizeof(RGBQUAD)); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 有了阿?memcpy(&(m_lpbyteBi.bmiColors),&(m_lpBi->bmiColors),sizeof(RGBQUAD));======================================================1 bit的调色板(如果有的话)和 8 bits的调色板大小是一样的吗?难怪会是黑色的了。 hDc=CreateCompatibleDC(NULL); hbyteDc=CreateCompatibleDC(NULL); SelectObject(hDc, m_hBitmap); SelectObject(hbyteDc, m_hbyteBitmap); memset(colortable,0,1024); GetDIBColorTable(hDc, 0, 2, colortable); SetDIBColorTable(hbyteDc, 0, 256, colortable); DeleteDC(hbyteDc); DeleteDC(hDc); 加上了颜色表处理,图像怎么变形了?代码见下:1bit->8bit:其中m_lpBi,m_lpbuf 是原始图像的信息和图像数据;void CTestBitDoc::On1To8() { // TODO: Add your command handler code here int i,j,k,m,ln; char *tmp_fbuf; char* pbyte; FILE* fp; BITMAPFILEHEADER BFH; FILE *fp1; int BmSize; RGBQUAD colortable[256]; HDC hDc,hbyteDc; m_lpbyteBi=(LPBITMAPINFO)malloc(40+4*256); memcpy(m_lpbyteBi, m_lpBi, 40); m_lpbyteBi->bmiHeader.biBitCount = 8; m_lpbyteBi->bmiHeader.biSizeImage = m_lpBi->bmiHeader.biWidth*m_lpBi->bmiHeader.biHeight; m_hbyteBitmap=CreateDIBSection(NULL,m_lpbyteBi,DIB_RGB_COLORS,(void**)&m_lpnbuf,NULL,0); hDc=CreateCompatibleDC(NULL); hbyteDc=CreateCompatibleDC(NULL); SelectObject(hDc, m_hBitmap); SelectObject(hbyteDc, m_hbyteBitmap); memset(colortable,0,1024); GetDIBColorTable(hDc, 0, 2, colortable); SetDIBColorTable(hbyteDc, 0, 256, colortable); DeleteDC(hbyteDc); DeleteDC(hDc); pbyte=(char*)malloc(m_lpBi->bmiHeader.biHeight*m_lpBi->bmiHeader.biWidth); tmp_fbuf=pbyte; for(i=m_lpBi->bmiHeader.biHeight; i>0; i--) { ln=0; for(j=0; j<((m_lpBi->bmiHeader.biWidth*m_lpBi->bmiHeader.biBitCount+31)/32*4); j++) { for(k=0,m=0x80; k<8; k++) { if(ln<m_lpBi->bmiHeader.biWidth) { *tmp_fbuf=(*m_lpbuf) & m; tmp_fbuf++; } ln++; m=m>>1; } m_lpbuf++; } } memcpy(m_lpnbuf, pbyte, m_lpbyteBi->bmiHeader.biSizeImage); free(pbyte); fclose(fp); UpdateAllViews(NULL);} LPRGBQUAD lpColor;int nColors = 256*sizeof(RGBQUAD); lpColor = new RGBQUAD[256]; memset(lpColor, 0, nColors); for(int i = 0; i < 256; i ++) { lpColor[i].rgbBlue = i; lpColor[i].rgbGreen = i; lpColor[i].rgbRed = i; } 新年快乐!!!!! 问一个关于数据接收的问题 WINDOWS任务栏按钮排序的原理 这样是不是很无耻??? 关于宏的问题 头文件的问题。 怎样实现将程序最小化到系统托盘? 100分送给大家!!! 关于CreateFile以及CreateProcess的问题. 如合在一个软件项目中综合利用多种编程语言 求助:如何使用DLL中导出的变量 散分,散分 ^ ^顺便做个广告
memcpy(&(m_lpbyteBi.bmiColors),&(m_lpBi->bmiColors),sizeof(RGBQUAD));======================================================1 bit的调色板(如果有的话)和 8 bits的调色板大小是一样的吗?难怪会是黑色的了。
hbyteDc=CreateCompatibleDC(NULL);
SelectObject(hDc, m_hBitmap);
SelectObject(hbyteDc, m_hbyteBitmap);
memset(colortable,0,1024);
GetDIBColorTable(hDc, 0, 2, colortable);
SetDIBColorTable(hbyteDc, 0, 256, colortable);
DeleteDC(hbyteDc);
DeleteDC(hDc);
加上了颜色表处理,图像怎么变形了?
代码见下:
1bit->8bit:其中m_lpBi,m_lpbuf 是原始图像的信息和图像数据;
void CTestBitDoc::On1To8()
{
// TODO: Add your command handler code here
int i,j,k,m,ln;
char *tmp_fbuf;
char* pbyte;
FILE* fp;
BITMAPFILEHEADER BFH;
FILE *fp1;
int BmSize;
RGBQUAD colortable[256];
HDC hDc,hbyteDc;
m_lpbyteBi=(LPBITMAPINFO)malloc(40+4*256);
memcpy(m_lpbyteBi, m_lpBi, 40);
m_lpbyteBi->bmiHeader.biBitCount = 8;
m_lpbyteBi->bmiHeader.biSizeImage = m_lpBi->bmiHeader.biWidth*m_lpBi->bmiHeader.biHeight;
m_hbyteBitmap=CreateDIBSection(NULL,m_lpbyteBi,DIB_RGB_COLORS,(void**)&m_lpnbuf,NULL,0);
hDc=CreateCompatibleDC(NULL);
hbyteDc=CreateCompatibleDC(NULL);
SelectObject(hDc, m_hBitmap);
SelectObject(hbyteDc, m_hbyteBitmap);
memset(colortable,0,1024);
GetDIBColorTable(hDc, 0, 2, colortable);
SetDIBColorTable(hbyteDc, 0, 256, colortable);
DeleteDC(hbyteDc);
DeleteDC(hDc);
pbyte=(char*)malloc(m_lpBi->bmiHeader.biHeight*m_lpBi->bmiHeader.biWidth);
tmp_fbuf=pbyte;
for(i=m_lpBi->bmiHeader.biHeight; i>0; i--)
{
ln=0;
for(j=0; j<((m_lpBi->bmiHeader.biWidth*m_lpBi->bmiHeader.biBitCount+31)/32*4); j++)
{
for(k=0,m=0x80; k<8; k++)
{
if(ln<m_lpBi->bmiHeader.biWidth)
{
*tmp_fbuf=(*m_lpbuf) & m;
tmp_fbuf++;
}
ln++;
m=m>>1;
}
m_lpbuf++;
}
}
memcpy(m_lpnbuf, pbyte, m_lpbyteBi->bmiHeader.biSizeImage);
free(pbyte);
fclose(fp);
UpdateAllViews(NULL);
}
int nColors = 256*sizeof(RGBQUAD);
lpColor = new RGBQUAD[256];
memset(lpColor, 0, nColors);
for(int i = 0; i < 256; i ++)
{
lpColor[i].rgbBlue = i;
lpColor[i].rgbGreen = i;
lpColor[i].rgbRed = i;
}