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

📄 dib.cpp

📁 用于网络传输时的Jpg和Bmp格式相互转换的API封装
💻 CPP
📖 第 1 页 / 共 4 页
字号:
		{
			i += nDeta;
			if (i > GetWidth()/2)
			{
				i = GetWidth()/2;
				bDone = TRUE;
			}
			pDC->BitBlt(x,  			//x dest
						y,		//y dest
	      				GetWidth()/2-i,		//width
						GetHeight(),	//depth
						&MemDC,
						i,			//y source
						0,				//x source
						SRCCOPY);

			pDC->BitBlt(x+GetWidth()/2+i,  			//x dest
						y,		//y dest
      					GetWidth()/2-i,		//width
						GetHeight(),	//depth
						&MemDC,
						GetWidth()/2,				//x source
						0,			//y source
						SRCCOPY);

			pDC->Rectangle( x+GetWidth()/2-i,
							y,
							x+GetWidth()/2+i+1,
							y+GetHeight());
			break;
		}
		case EFFECT_VRASTER:
		{
			if (i > GetHeight())
			{
				i = GetHeight();
				bDone = TRUE;
			}
			LONG j = 0;
			BOOL bQuitLoop = FALSE;
			while (! bQuitLoop)
			{
				if (j > GetWidth())
				{
					j = GetWidth();
					bQuitLoop = TRUE;
				}
				pDC->BitBlt(x+j,  			//x dest
							y+i,		//y dest
      						nDeta,		//width
							GetHeight()-i,	//depth
							&MemDC,
							j,				//x source
							0,			//y source
							SRCCOPY);

				pDC->Rectangle(x+j, y+i-1,
							   x+j+nDeta, y+i);
				j += nDeta;
				if (j > GetWidth())
				{
					j = GetWidth();
					bQuitLoop = TRUE;
				}
	
				pDC->BitBlt(x+j,  			//x dest
							y,		//y dest
				  			nDeta,		//width
							GetHeight()-i,	//depth
							&MemDC,
							j,			//y source
							i,				//x source
							SRCCOPY);

				pDC->Rectangle( x+j,
								y+GetHeight()-i,
								x+j+nDeta,
								y+GetHeight());
				j += nDeta;
			}
			i++;
			break;
		}
		case EFFECT_HRASTER:
		{
			if (i > GetWidth())
			{
				i = GetWidth();
				bDone = TRUE;
			}
			LONG j = 0;
			BOOL bQuitLoop = FALSE;
			while (! bQuitLoop)
			{
				if (j > GetHeight())
				{
					j = GetHeight();
					bQuitLoop = TRUE;
				}
				pDC->BitBlt(x+i,  			//x dest
							y+j,		//y dest
      						GetWidth()-i,		//width
							nDeta,	//depth
							&MemDC,
							0,				//x source
							j,			//y source
							SRCCOPY);
				pDC->Rectangle(x+i-1, y+j,
							   x+i, y+j+nDeta);
				j += nDeta;
				if (j > GetHeight())
				{
					j = GetHeight();
					bQuitLoop = TRUE;
				}
				pDC->BitBlt(x,  			//x dest
							y+j,		//y dest
				  			GetWidth()-i,		//width
							nDeta,	//depth
							&MemDC,
							i,			//y source
							j,				//x source
							SRCCOPY);
				pDC->Rectangle( x+GetWidth()-i,
								y+j,
								x+GetWidth(),
								y+j+nDeta);
				j += nDeta;
			}
			i++;
			break;
		}
		case EFFECT_HBLIND:
		{
			if (i > nDeta)
			{
				i = nDeta;
				bDone = TRUE;
			}
			for (LONG j=i; j<GetHeight(); j+=nDeta)
				pDC->Rectangle( x,
								y+j,
								x+GetWidth(),
								y+j+1);
			i++;
			break;
		}
		case EFFECT_VBLIND:
			if (i > nDeta)
			{
				i = nDeta;
				bDone = TRUE;
			}
			for (LONG j=i; j<GetWidth(); j+=nDeta)
				pDC->Rectangle( x+j,
								y,
								x+j+1,
								y+GetHeight());
			i++;
			break;
		}	// end of switch
		Delay(dwDelayTime);
	}	// end of while

	MemDC.SelectObject(pOldBmp);
	pDC->SelectPalette(pOldPal, TRUE);

	return TRUE;
}

HDIB CDib::CopyRect(CRect rc)
{
	return CropDIB(m_hDib, rc);
}

BOOL CDib::CutRect(CRect rc)
{
	HDIB hNewDib = CutDIB(m_hDib, rc);
	if (! hNewDib)
		return FALSE;

	// set to m_hDib
	Destroy();
	m_hDib = hNewDib;

	// return
	return UpdateInternal();
}

BOOL CDib::MergeDib(HDIB hDib, CPoint ptTopLeft)
{
	POINT pt;
	pt.x = ptTopLeft.x;
	pt.y = ptTopLeft.y;
	HDIB hNewDib = MergeDIB(m_hDib, hDib, pt);
	if (! hNewDib)
		return FALSE;

	// set to m_hDib
	Destroy();
	m_hDib = hNewDib;

	// return
	return UpdateInternal();
}

BOOL CDib::TransparentMergeDib(HDIB hDib, CPoint ptTopLeft, COLORREF crTransparent)
{
	POINT pt;
	pt.x = ptTopLeft.x;
	pt.y = ptTopLeft.y;
	HDIB hNewDib = TransparentMergeDIB(m_hDib, hDib, pt, crTransparent);
	if (! hNewDib)
		return FALSE;

	// set to m_hDib
	Destroy();
	m_hDib = hNewDib;

	// return
	return UpdateInternal();
}

BOOL CDib::	Crop(CRect rc)
{
	HDIB hNewDib = CropDIB(m_hDib, rc);
	if (! hNewDib)
		return FALSE;

	// set to m_hDib
	Destroy();
	m_hDib = hNewDib;

	// return
	return UpdateInternal();
}

BOOL CDib::Rotate(double fDegrees, COLORREF clrBack)
{
	HDIB hNewDib = RotateDIB(m_hDib, fDegrees, clrBack);
	if (! hNewDib)
		return FALSE;

	// set to m_hDib
	Destroy();
	m_hDib = hNewDib;

	// return
	return UpdateInternal();
}

BOOL CDib::Rotate90()
{
	HDIB hNewDib = RotateDIB(m_hDib);
	if (! hNewDib)
		return FALSE;

	// set to m_hDib
	Destroy();
	m_hDib = hNewDib;

	// return
	return UpdateInternal();
}

BOOL CDib::Rotate180()
{
	HDIB h = RotateDIB(m_hDib);
	if (! h)
		return FALSE;
	HDIB hNewDib = RotateDIB(h);
	DestroyDIB(h);
	if (! hNewDib)
		return FALSE;

	// set to m_hDib
	Destroy();
	m_hDib = hNewDib;

	// return
	return UpdateInternal();
}

BOOL CDib::Rotate270()
{
	HDIB h1 = RotateDIB(m_hDib);
	if (! h1)
		return FALSE;
	HDIB h2 = RotateDIB(h1);
	DestroyDIB(h1);
	if (! h2)
		return FALSE;
	HDIB hNewDib = RotateDIB(h2);
	DestroyDIB(h2);
	if (! hNewDib)
		return FALSE;

	// set to m_hDib
	Destroy();
	m_hDib = hNewDib;

	// return
	return UpdateInternal();
}

BOOL CDib::FlipHorz()
{
	HDIB hNewDib = FlipHorzDIB(m_hDib);
	if (! hNewDib)
		return FALSE;

	// set to m_hDib
	Destroy();
	m_hDib = hNewDib;

	// return
	return UpdateInternal();
}

BOOL CDib::FlipVert()
{
	HDIB hNewDib = FlipVertDIB(m_hDib);
	if (! hNewDib)
		return FALSE;

	// set to m_hDib
	Destroy();
	m_hDib = hNewDib;

	// return
	return UpdateInternal();
}

BOOL CDib::	ChangeImageSize(int nWidth, int nHeight)
{
	HDIB hNewDib = ChangeDIBSize(m_hDib, nWidth, nHeight);
	if (! hNewDib)
		return FALSE;

	// set to m_hDib
	Destroy();
	m_hDib = hNewDib;

	// return
	return UpdateInternal();
}

BOOL CDib::Zoom(double fRatioX, double fRatioY)
{
	int nWidth = (int)(fRatioX * (double)GetWidth());
	int nHeight = (int)(fRatioY * (double)GetHeight());

	HDIB hNewDib = ChangeDIBSize(m_hDib, nWidth, nHeight);
	if (! hNewDib)
		return FALSE;

	// set to m_hDib
	Destroy();
	m_hDib = hNewDib;

	// return
	return UpdateInternal();
}

BOOL CDib::	ChangeCanvasSize(int nWidth, int nHeight, int nPosition)
{
	HDIB hNewDib = ChangeDIBCanvasSize(m_hDib, nWidth, nHeight, nPosition);
	if (! hNewDib)
		return FALSE;

	// set to m_hDib
	Destroy();
	m_hDib = hNewDib;

	// return
	return UpdateInternal();
}

BOOL CDib::IsRequireDither(CDC* pDC)
{
	// if device can not display DIB color, dithering DIB
	if (GetBitCount() > 8 && 
		pDC->GetDeviceCaps(BITSPIXEL) <= 8)
		return TRUE;

	return FALSE;
}

BOOL CDib::DitherDisplay(CDC* pDC, CRect rcDest, CRect rcSrc, DWORD dwRop)
{
	return DitherDisplayDIB(pDC->GetSafeHdc(), 
							rcDest, 
							m_hDib, 
							rcSrc, 
							dwRop);
}

BOOL CDib::AdjustColor(int nColorModel, int v1, int v2, int v3)
{
	if (! AdjustDIBColor(m_hDib, nColorModel, v1, v2, v3))
		return FALSE;

	return UpdateInternal();
}

BOOL CDib::AdjustBrightness(int v)
{
	if (! AdjustDIBBrightness(m_hDib, v))
		return FALSE;

	return UpdateInternal();
}

BOOL CDib::AdjustContrast(int v)
{
	if (! AdjustDIBContrast(m_hDib, v))
		return FALSE;

	return UpdateInternal();
}

BOOL CDib::SeparateRGB(int nIndex)
{
	HDIB hNewDib = SeparateRGBfromDIB(m_hDib, nIndex);
	if (! hNewDib)
		return FALSE;

	// set to m_hDib
	Destroy();
	m_hDib = hNewDib;

	// return
	return UpdateInternal();
}

BOOL CDib::FilteRGB(int nIndex)
{
	HDIB hNewDib = FilteRGBfromDIB(m_hDib, nIndex);
	if (! hNewDib)
		return FALSE;

	// set to m_hDib
	Destroy();
	m_hDib = hNewDib;

	// return
	return UpdateInternal();
}

BOOL CDib::ColorQuantize(int nColorBits)
{
	HDIB hNewDib;

	if (nColorBits > 8)
		hNewDib = ConvertDIBFormat(m_hDib, nColorBits, NULL); 
	else
	{
		int nColors = 1<<nColorBits;
		hNewDib = ColorQuantizeDIB(m_hDib, nColorBits, nColors);
	}

	if (! hNewDib)
		return FALSE;

	Destroy();
	m_hDib = hNewDib;
	
	return UpdateInternal();
}

BOOL CDib::ChangeToGrayscale(int nMethod, double fRedWeight, double fGreenWeight, double fBlueWeight)
{
	HPALETTE hPal = ConvertToGrayscale(m_hDib, nMethod, fRedWeight, fGreenWeight, fBlueWeight);
	if (hPal == NULL)
		return FALSE;

	// set new palette
	if (m_pPalette != NULL)
		delete m_pPalette;

	m_pPalette = new CPalette;
	m_pPalette->Attach(hPal);

	// rebuild bitmap
	return UpdateInternal();
}

BOOL CDib::HighPass(int Strength, int nAlgorithm)
{
	if (IsEmpty())
		return FALSE;

	if (! HighPassDIB(m_hDib, Strength, nAlgorithm))
		return FALSE;

	// return
	return UpdateInternal();
}

BOOL CDib::LowPass(int Strength, int nAlgorithm)
{
	if (IsEmpty())
		return FALSE;

	if (! LowPassDIB(m_hDib, Strength, nAlgorithm))
		return FALSE;

	// return
	return UpdateInternal();
}

BOOL CDib::EdgeEnhance(int Strength, int nAlgorithm)
{
	if (IsEmpty())
		return FALSE;

	if (! EdgeEnhanceDIB(m_hDib, Strength, nAlgorithm))
		return FALSE;

	// return
	return UpdateInternal();
}

BOOL CDib::MedianFilter()
{
	if (IsEmpty())
		return FALSE;

	if (! MedianFilterDIB(m_hDib))
		return FALSE;

	// return
	return UpdateInternal();
}

BOOL CDib::ConvertFormat(WORD wBitCount)
{
	if (IsEmpty())
		return FALSE;

	if (GetBitCount() == wBitCount)
		return TRUE;

	HDIB hNewDib = ConvertDIBFormat(m_hDib, wBitCount, NULL); 
	if (! hNewDib)
		return FALSE;

	Destroy();
	m_hDib = hNewDib;
	return UpdateInternal();
}

BOOL CDib::Erosion(BOOL bHoriz)
{
	if (IsEmpty())
		return FALSE;

	if (! ErosionDIB(m_hDib, bHoriz))
		return FALSE;

	// return
	return UpdateInternal();
}

BOOL CDib::Dilation(BOOL bHoriz)
{
	if (IsEmpty())
		return FALSE;

	if (! DilationDIB(m_hDib, bHoriz))
		return FALSE;

	// return
	return UpdateInternal();
}

BOOL CDib::MorphOpen(BOOL bHoriz)
{
	if (IsEmpty())
		return FALSE;

	if (! MorphOpenDIB(m_hDib, bHoriz))
		return FALSE;

	// return
	return UpdateInternal();
}

BOOL CDib::MorphClose(BOOL bHoriz)
{
	if (IsEmpty())
		return FALSE;

	if (! MorphCloseDIB(m_hDib, bHoriz))
		return FALSE;

	// return
	return UpdateInternal();
}

BOOL CDib::Contour(BOOL bHoriz)
{
	if (IsEmpty())
		return FALSE;

	if (! ContourDIB(m_hDib, bHoriz))
		return FALSE;

	// return
	return UpdateInternal();
}

BOOL CDib::Thinning()
{
	if (IsEmpty())
		return FALSE;

	if (! ThinningDIB(m_hDib))
		return FALSE;

	// return
	return UpdateInternal();
}

BOOL CDib::Reverse()
{
	if (IsEmpty())
		return FALSE;

	if (! ReverseDIB(m_hDib))
		return FALSE;

	// return
	return UpdateInternal();
}

BOOL CDib::FFT()
{
	if (IsEmpty())
		return FALSE;

	if (! FFTDIB(m_hDib))
		return FALSE;

	// return
	return UpdateInternal();
}

BOOL CDib::DCT()
{
	if (IsEmpty())
		return FALSE;

	if (! DCTDIB(m_hDib))
		return FALSE;

	// return
	return UpdateInternal();
}

BOOL CDib::WALh()
{
	if (IsEmpty())
		return FALSE;

	if (! WALhDIB(m_hDib))
		return FALSE;

	// return
	return UpdateInternal();
}

⌨️ 快捷键说明

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