📄 dib.cpp
字号:
GetHeight()-i, //depth
&MemDC,
0, //x source
0, //y source
SRCCOPY);
pDC->Rectangle(x, y+i-nDeta,
x+GetWidth()/2, y+i);
pDC->BitBlt(x+GetWidth()/2, //x dest
y, //y dest
GetWidth(), //width
GetHeight()-i, //depth
&MemDC,
GetWidth()/2, //x source
i, //y source
SRCCOPY);
pDC->Rectangle( x+GetWidth()/2,
y+GetHeight()-i,
x+GetWidth(),
y+GetHeight());
break;
}
case EFFECT_HCROSSMOVE:
{
i += nDeta;
if (i > GetWidth())
{
i = GetWidth();
bDone = TRUE;
}
pDC->BitBlt(x+i, //x dest
y, //y dest
GetWidth()-i, //width
GetHeight()/2, //depth
&MemDC,
0, //x source
0, //y source
SRCCOPY);
pDC->Rectangle(x+i-nDeta, y,
x+i, y+GetHeight()/2);
pDC->BitBlt(x, //x dest
y+GetHeight()/2, //depth
GetWidth()-i, //width
GetHeight(), //depth
&MemDC,
i, //y source
GetHeight()/2, //depth
SRCCOPY);
pDC->Rectangle( x+GetWidth()-i,
y+GetHeight()/2,
x+GetWidth(),
y+GetHeight());
break;
}
case EFFECT_VSPLITMOVE:
{
i += nDeta;
if (i > GetHeight()/2)
{
i = GetHeight()/2;
bDone = TRUE;
}
pDC->BitBlt(x, //x dest
y, //y dest
GetWidth(), //width
GetHeight()/2-i, //depth
&MemDC,
0, //x source
i, //y source
SRCCOPY);
pDC->BitBlt(x, //x dest
y+GetHeight()/2+i, //y dest
GetWidth(), //width
GetHeight()/2-i, //depth
&MemDC,
0, //x source
GetHeight()/2, //y source
SRCCOPY);
pDC->Rectangle( x,
y+GetHeight()/2-i,
x+GetWidth(),
y+GetHeight()/2+i+1);
break;
}
case EFFECT_HSPLITMOVE:
{
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:: 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::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() == 24 &&
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 (! HighPassDIB(m_hDib, Strength, nAlgorithm))
return FALSE;
// return
return UpdateInternal();
}
BOOL CDib::LowPass(int Strength, int nAlgorithm)
{
if (! LowPassDIB(m_hDib, Strength, nAlgorithm))
return FALSE;
// return
return UpdateInternal();
}
BOOL CDib::EdgeEnhance(int Strength, int nAlgorithm)
{
if (! EdgeEnhanceDIB(m_hDib, Strength, nAlgorithm))
return FALSE;
// return
return UpdateInternal();
}
BOOL CDib::MedianFilter()
{
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();
}
BYTE CDib::GetPixel8(LONG x, LONG y)
{
BYTE result;
switch (GetBitCount())
{
case 1 : result = 0;
break;
case 4 : result = 0;
break;
case 8 :
{
result = *(BYTE*)(GetBitsPtr()+GetPixelOffset(x, y));
}
break;
default: result = 0;
break;
}
return result;
}
BOOL CDib::SetPixel8(LONG x, LONG y, BYTE value)
{
if(GetBitCount() != 8)
return false;
else
{
*(BYTE*)(GetBitsPtr()+GetPixelOffset(x, y)) = value;
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -