⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drawimage.c

📁 图像处理软件,功能比较基础
💻 C
字号:
void CPlantView::DrawImage(HDC m_hDC, unsigned char * * pImage2d, int Row, int Col)
{
	short iRow,iCol;

	pImage = PrepareShowBMP(pImage2d,Row,Col,
		pbmpfileheader,rgbq, plgpl, pbmi, &iRow, &iCol);

//	CPalette *pPal = new CPalette;
    HPALETTE hPal;
	
	hPal = ::CreatePalette(plgpl);
	if(hPal == NULL) {
		MessageBeep(0);
		MessageBox("Can't create palette!","Error");
	}
	
	HPALETTE hPalOld = ::SelectPalette(m_hDC,hPal,FALSE);
	RealizePalette(m_hDC);

	HBITMAP hBitmap = ::CreateDIBitmap(m_hDC,
		(BITMAPINFOHEADER FAR *)&(pbmi->bmiHeader),
		CBM_INIT, pImage, (LPBITMAPINFO)pbmi,DIB_RGB_COLORS);
	HDC hMemDC = ::CreateCompatibleDC(m_hDC);

	HBITMAP hBitmapOld = (HBITMAP)::SelectObject(hMemDC,hBitmap);
	::StretchBlt(m_hDC,0,0,iCol,iRow,hMemDC,0,0,iCol,iRow,SRCCOPY);
	hBitmap = (HBITMAP)::SelectObject(hMemDC,hBitmapOld);
	::DeleteObject(hBitmap);
	::DeleteDC(hMemDC);
	delete pImage;
}

unsigned char * CPlantView::PrepareShowBMP(unsigned char * * pImage2d, short Row, short Col, PBITMAPFILEHEADER pbmpfileheader, RGBQUAD * rgbq, LPLOGPALETTE plgpl, PBITMAPINFO pbmi, short * iRow, short * iCol)
{
	unsigned char *pImage;
	short i;
	//	pbmpfileheader = new BITMAPFILEHEADER;
	pbmpfileheader->bfType = (WORD)0x4d42;
	pbmpfileheader->bfSize = (long)Row*Col+54L+4*256L;
	pbmpfileheader->bfReserved1 = 0;
	pbmpfileheader->bfReserved2 = 0;
	pbmpfileheader->bfOffBits = 54+4*256;

//	RGBQUAD rgbq[256];

	for(i=0;i<256;i++) {
		rgbq[i].rgbRed	=	(unsigned char)i;
		rgbq[i].rgbBlue	=	(unsigned char)i;
		rgbq[i].rgbGreen=	(unsigned char)i;
		rgbq[i].rgbReserved	=	0;
	}

//	plgpl = (LPLOGPALETTE)new unsigned char[sizeof(LOGPALETTE) +
//				256*sizeof(PALETTEENTRY)];
	plgpl->palNumEntries = 256;
	plgpl->palVersion = 0x300;

	for(i=0;i<256;i++) {
		plgpl->palPalEntry[i].peRed = rgbq[i].rgbRed;
		plgpl->palPalEntry[i].peGreen = rgbq[i].rgbGreen;
		plgpl->palPalEntry[i].peBlue = rgbq[i].rgbBlue;
		plgpl->palPalEntry[i].peFlags = 0;
	}

/*	if((Col*8%32) 
		iCol = Col+4;
	else 
		iCol = Col;
*/
    *iCol=((Col+3)/4)*4;
	*iRow = Row;

//	pbmi = (PBITMAPINFO)new unsigned char[sizeof(BITMAPINFOHEADER)
//				+sizeof(RGBQUAD)*256];
	pbmi->bmiHeader.biSize = 40L;
	pbmi->bmiHeader.biWidth = Col;
	pbmi->bmiHeader.biHeight = Row;
	pbmi->bmiHeader.biPlanes = 1L;
	pbmi->bmiHeader.biBitCount = 8L;
	pbmi->bmiHeader.biCompression = 0L;
	pbmi->bmiHeader.biSizeImage = (long)Row*Col;
	pbmi->bmiHeader.biXPelsPerMeter = 0xbc;
	pbmi->bmiHeader.biYPelsPerMeter = 0xbc;
	pbmi->bmiHeader.biClrUsed = 256;
	pbmi->bmiHeader.biClrImportant = 0;

	memcpy(pbmi->bmiColors,rgbq,sizeof(RGBQUAD)*256);


	pImage = new unsigned char[(long)Row*(*iCol)];
	if(!pImage) return NULL;

	for(i=Row-1;i>=0;i--)
		memcpy(pImage+(long)(Row-i-1)*(*iCol),pImage2d[i],Col);

	return pImage;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -