本文整理汇总了C++中CDib::Attach方法的典型用法代码示例。如果您正苦于以下问题:C++ CDib::Attach方法的具体用法?C++ CDib::Attach怎么用?C++ CDib::Attach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDib
的用法示例。
在下文中一共展示了CDib::Attach方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Save
// save Jpeg file
BOOL CJpeg::Save(LPCSTR lpstrFileName, CDib* pDib, BOOL bColor, int nQuality)
{
if (pDib == NULL)
pDib = m_pDib;
if (pDib == NULL)
return FALSE;
HDIB hDib = CopyHandle(pDib->GetHandle());
if (hDib == NULL)
return FALSE;
CDib* pDibTmp = new CDib;
pDibTmp->Attach(hDib);
if (pDibTmp->GetBitCount() != 24)
pDibTmp->ConvertFormat(24);
UINT uWidth = pDibTmp->GetWidth();
UINT uHeight = pDibTmp->GetHeight();
// convert from DIB format (DWORD aligned, vertically flipped, red and blue swapped)
BYTE* tmp = ClearDwordAlign(pDibTmp->GetBitsPtr(),
uWidth,
WIDTHBYTES(uWidth * 24),
uHeight);
if (tmp == NULL)
return FALSE;
// convert from DIB
VertFlipBuf(tmp, uWidth*3, uHeight);
BGRFromRGB(tmp, uWidth, uHeight);
BOOL bSuccess = WriteJPEGFile(lpstrFileName,
tmp,
uWidth,
uHeight,
bColor,
nQuality);
delete pDibTmp;
FreeBuffer(tmp);
return bSuccess;
}
示例2: SavePcx
//******************* 保存为PCX (由CDib对象) ***********************
BOOL LanImage::SavePcx(LPCTSTR lpstrFileName, CDib* pDib)
{
int i = 0;
if (pDib == NULL)
return FALSE;
HDIB hDib = CopyHandle(pDib->GetHandle());
if (hDib == NULL)
return FALSE;
CDib* pDibTmp = new CDib();
pDibTmp->Attach(hDib);
UINT uWidth = pDibTmp->GetWidth();
UINT uHeight = pDibTmp->GetHeight();
// 当打开的图像BitCount不为8时,转为8位格式
if (pDibTmp->GetBitCount() != 8)
pDibTmp->ConvertFormat(8);
// make PCX header
PCXHEAD header;
memset((LPBYTE)&header, 0, sizeof(PCXHEAD));
header.manufacturer = 0x0A;
header.version = 5;
header.encoding = 1;
header.bit_per_pixel = 8;
//header.bit_per_pixel = 24;
header.xmin = 0;
header.ymin = 0;
header.xmax = uWidth-1;
header.ymax = uHeight-1;
//header.Xresolution;
//header.Yresolution;
header.palette[0] = (BYTE)0x00; // for correct process for mono
header.palette[1] = (BYTE)0x00;
header.palette[2] = (BYTE)0x00;
header.palette[3] = (BYTE)0xff;
header.palette[4] = (BYTE)0xff;
header.palette[5] = (BYTE)0xff;
//header.palette[48];
header.reserved = 0;
header.color_planes = 1;
header.byte_per_line = uWidth;
header.palette_type = 1;
//filler[58];
// construct PCX palette from DIB color table
PCXPALETTE palette[256];
PALETTEENTRY PaletteColors[256];
pDibTmp->GetPalette()->GetPaletteEntries(0, 256, PaletteColors);
for (i=0;i<256;i++)
{
palette[i].rgbRed = PaletteColors[i].peRed;
palette[i].rgbGreen = PaletteColors[i].peGreen;
palette[i].rgbBlue = PaletteColors[i].peBlue;
}
// get bits ptr
HDIB hDIB = CopyHandle(pDibTmp->GetHandle());
delete pDibTmp;
LPBYTE lpDIB = (LPBYTE)GlobalLock(hDIB);
BYTE* lpBuffer = (BYTE *)FindDIBBits(lpDIB);
WORD wWidthBytes = (WORD)BytesPerLine(lpDIB);
/*** Open the PCX file ***/
FILE *outFile;
if ((outFile=fopen(lpstrFileName,"wb")) == NULL)
{
GlobalUnlock(hDIB);
GlobalFree(hDIB);
return FALSE;
}
/*** Write the header ***/
fwrite((char *)&header, sizeof(PCXHEAD), 1, outFile);
/*** Write image data ***/
for ( i=(int)uHeight-1; i>=0; --i)
{
if (! WritePCXLine(header.byte_per_line, lpBuffer+i*wWidthBytes, outFile))
{
fclose(outFile);
GlobalUnlock(hDIB);
GlobalFree(hDIB);
return FALSE;
}
}
/*** Write the palette data ***/
fputc(0x0c, outFile);
fwrite((char *)palette, 1, sizeof(palette), outFile);
// clear & close
fclose(outFile);
GlobalUnlock(hDIB);
GlobalFree(hDIB);
return TRUE;
//.........这里部分代码省略.........