本文整理汇总了C++中StretchDIBits函数的典型用法代码示例。如果您正苦于以下问题:C++ StretchDIBits函数的具体用法?C++ StretchDIBits怎么用?C++ StretchDIBits使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StretchDIBits函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetWidth
void
Dib::Render (/*[in]*/ HDC hdc,
/*[in]*/ int x,
/*[in]*/ int y,
/*[in]*/ int cx,
/*[in]*/ int cy)
{
if (cx < 0)
{
cx = GetWidth();
}
if (cy < 0)
{
cy = GetHeight();
}
SetStretchBltMode (hdc, COLORONCOLOR);
if (StretchDIBits(hdc,
x,
y,
cx,
cy,
0,
0,
GetWidth(),
GetHeight(),
GetBits(),
GetBitmapInfo(),
DIB_RGB_COLORS,
SRCCOPY)
== GDI_ERROR)
{
FATAL_WINDOWS_ERROR ("StretchDIBits", 0);
}
}
示例2: WndProc
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM w, LPARAM l)
{
HDC hdc;// = GetDC(hwnd);
PAINTSTRUCT ps;
RECT rect;
BITMAPINFO bmi;
ZeroMemory(&bmi, sizeof(BITMAPINFO));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biCompression = BI_RGB;
switch (msg) {
case WM_DESTROY:
PostQuitMessage(1);
break;
case WM_PAINT: {
hdc=BeginPaint(hwnd,&ps);
//GetWindowRect(hwnd,&rect);
//RedrawWindow(hwnd,&rect,0,0);
if(num==vs.length-1)exit(0);
readjpeg(vs.strs[num++], &img);
bmi.bmiHeader.biWidth = img.Width;
bmi.bmiHeader.biHeight = img.Height;
//SetDIBitsToDevice(hdc, 0, 0, img.Width, img.Height,0, 0, 0, img.Height, img.Data, &bmi, DIB_RGB_COLORS);
SetStretchBltMode(hdc,STRETCH_HALFTONE);//注意第二个参数会影响显示质量
StretchDIBits(hdc, 0, 0, img.Width/2, img.Height/2,0, 0,img.Width,img.Height, img.Data, &bmi, DIB_RGB_COLORS,SRCCOPY);
free(img.Data);
EndPaint(hwnd,&ps);
}
break;
default:
return DefWindowProc(hwnd, msg, w, l);
}
return 0;
}
示例3: DrawDIB
//
// DrawDib uses StretchDIBits to display the bitmap.
void CDIBitmap :: DrawDIB( CDC* pDC, int x, int y, int width, int height ) {
ASSERT( pDC );
HDC hdc = pDC->GetSafeHdc();
CPalette * pOldPal = 0;
if( m_pPal ) {
pOldPal = pDC->SelectPalette( m_pPal, FALSE );
pDC->RealizePalette();
// Make sure to use the stretching mode best for color pictures
pDC->SetStretchBltMode(COLORONCOLOR);
}
if( m_pInfo )
StretchDIBits( hdc,
x,
y,
width,
height,
0,
0,
GetWidth(),
GetHeight(),
GetPixelPtr(),
GetHeaderPtr(),
DIB_RGB_COLORS,
SRCCOPY );
if( m_pPal )
pDC->SelectPalette( pOldPal, FALSE );
}
示例4: dib_to_hdc
/*! \param hdc Destination DC.
* \param rectDest Destination rectangle. If NULL, the DIB's
* dimensions are used.
* \param dib DIB to blit.
* \param rectSrc Source rectangle. If NULL, the DIB's
* dimensions is used.
* \param flags Blit flags.
* \note Tested for top-down and bottom-up DIB's
*/
int dib_to_hdc(HDC hdc, const RECT *rectDst,
CLDIB *dib, const RECT *rectSrc, DWORD flags)
{
RECT dstR, srcR;
int dibHa= dib_get_height(dib);
if(rectDst == NULL)
SetRect(&dstR, 0, 0, dib_get_width(dib), dibHa);
else
CopyRect(&dstR, rectDst);
if(rectSrc == NULL)
SetRect(&srcR, 0, 0, dib_get_width(dib), dibHa);
else
CopyRect(&srcR, rectSrc);
int srcW= srcR.right-srcR.left, srcH= srcR.bottom-srcR.top;
int dstW= dstR.right-dstR.left, dstH= dstR.bottom-dstR.top;
SetStretchBltMode(hdc, COLORONCOLOR);
return StretchDIBits( hdc,
dstR.left, dstR.bottom, dstW, -dstH,
srcR.left, dibHa-srcR.top, srcW, -srcH,
dib_get_img(dib), dib_get_info(dib),
DIB_RGB_COLORS, flags);
}
示例5: memcpy_s
void CWebkitUI::DoPaint(HDC hDC, const RECT& rcPaint)
{
if ((hDC == NULL) || (raster_ == NULL) || (bitmap_bits_ == NULL) || !finish_layout_)
return;
if( !::IntersectRect(&m_rcPaint, &rcPaint, &m_rcItem) ) return;
if (did_first_layout_ && bitmap_bits_ != NULL && finish_layout_)
{
for (int i = 0; i < bitmap_header_info_.biHeight; ++i)
{
memcpy_s(bitmap_bits_ + (bitmap_header_info_.biWidth * i * 4), \
bitmap_header_info_.biSizeImage / bitmap_header_info_.biHeight, \
(LPBYTE)view_->GetSurface()->GetData() + (bitmap_header_info_.biWidth * i * 4), \
(bitmap_header_info_.biWidth * 4));
}
}
else if (bitmap_bits_ != NULL)
{
DWORD dwScreenX = GetSystemMetrics(SM_CXSCREEN);
DWORD dwScreenY = GetSystemMetrics(SM_CYSCREEN);
dwScreenX = static_cast<DWORD>((dwScreenX + 3) / 4 * 4);
memset(bitmap_bits_, 0xFF, dwScreenX * dwScreenY * 4);
}
::SetStretchBltMode(hDC, COLORONCOLOR);
BITMAPINFOHEADER bmiHeader = bitmap_header_info_;
bmiHeader.biHeight = -bmiHeader.biHeight;
StretchDIBits(hDC, m_rcItem.left, m_rcItem.top, m_rcItem.right - m_rcItem.left, m_rcItem.bottom - m_rcItem.top,
0, 0, bitmap_header_info_.biWidth, bitmap_header_info_.biHeight, bitmap_bits_, (LPBITMAPINFO)&bmiHeader, DIB_RGB_COLORS, SRCCOPY);
}
示例6: capEditCopy
Bool CWinVideoGrabber::Draw(int twidth,int theight, HDC hdcMem)
{
if (!inited) return False;
HGLOBAL videodib = NULL;
char *dibdata = NULL;
char *dibbits = NULL;
BITMAPINFO *pbmp;
Bool res = False;
capEditCopy(videowindow); // Copy the frame in the clipboard as a DIB
OpenClipboard(parentwindow);
if (IsClipboardFormatAvailable(CF_DIB)){
videodib=GetClipboardData(CF_DIB);
dibdata = (char *)GlobalLock(videodib);
pbmp = (BITMAPINFO *)dibdata;
int tsourcewidth = pbmp->bmiHeader.biWidth;
int tsourceheight = pbmp->bmiHeader.biHeight;
int palentries = pbmp->bmiHeader.biClrUsed;
int bitcount = pbmp->bmiHeader.biBitCount;
int lenrgb = 0;
if (bitcount < 24) {
if (palentries == 0)
palentries = (1 << bitcount);
lenrgb = palentries * sizeof(RGBQUAD);
}
dibbits = (char *)(dibdata + sizeof(BITMAPINFOHEADER) + lenrgb);
StretchDIBits(hdcMem,0,0,twidth,theight,0,0,tsourcewidth,tsourceheight,
(BITMAPINFO *)dibbits, pbmp, DIB_RGB_COLORS,SRCCOPY);
GlobalUnlock(videodib);
res = True;
}
CloseClipboard();
return res;
}
示例7: CreateDCCompatiblePattern
BOOL CreateDCCompatiblePattern(RGBQUAD color1, RGBQUAD color2, CDC *pDC, CBitmap *pbm)
{
RGBQUAD HatchBits[16] = { color1, color1, color2, color2, color1, color1, color2, color2,
color2, color2, color1, color1, color2, color2, color1, color1 };
BITMAPINFO bmi = { 0 };
bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biWidth = 4;
bmi.bmiHeader.biHeight = 4;
bmi.bmiHeader.biPlanes = 1;
CDC dcMem;
BOOL bRet = dcMem.CreateCompatibleDC(pDC);
if (bRet)
{
bRet = pbm->CreateCompatibleBitmap(pDC, 4, 4);
if (bRet)
{
HGDIOBJ hObj = dcMem.SelectObject(pbm);
bRet = StretchDIBits((HDC)dcMem, 0, 0, 4, 4, 0, 0, 4, 4, HatchBits, &bmi, DIB_RGB_COLORS, SRCCOPY);
dcMem.SelectObject(hObj);
}
}
return bRet;
}
示例8: gdi_softpipe_present
static void
gdi_softpipe_present(struct pipe_screen *screen,
struct pipe_surface *surface,
HDC hDC)
{
struct softpipe_texture *texture;
struct gdi_softpipe_buffer *buffer;
BITMAPINFO bmi;
texture = softpipe_texture(surface->texture);
buffer = gdi_softpipe_buffer(texture->buffer);
memset(&bmi, 0, sizeof(BITMAPINFO));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = texture->stride[surface->level] / pf_get_size(surface->format);
bmi.bmiHeader.biHeight= -(long)surface->height;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = pf_get_bits(surface->format);
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = 0;
bmi.bmiHeader.biXPelsPerMeter = 0;
bmi.bmiHeader.biYPelsPerMeter = 0;
bmi.bmiHeader.biClrUsed = 0;
bmi.bmiHeader.biClrImportant = 0;
StretchDIBits(hDC,
0, 0, surface->width, surface->height,
0, 0, surface->width, surface->height,
buffer->data, &bmi, 0, SRCCOPY);
}
示例9: StretchDIBits
/*======================================================================================*/
int CRaster::Draw(CDC* pDC, RECT , RECT)
{
HDC hDC;
CPalette* oldPal;
oldPal = 0;
hDC = pDC->m_hDC;
if(pal) {
oldPal = pDC->SelectPalette(pal, TRUE);
}/* if */
pDC->SetStretchBltMode(COLORONCOLOR);
StretchDIBits( hDC,
XDest, YDest,
DestWidth, DestHeight,
XSrc, YSrc,
SrcWidth, SrcHeight,
imgData, imgInfo,
DIB_RGB_COLORS, SRCCOPY);
if(pal) {
pDC->SelectPalette(oldPal, TRUE);
}/* if */
return 1;
}/* CRaster::Draw */
示例10: dc
void COriginalImg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CWnd *pWnd = GetDlgItem(IDC_ORGIMG);
if (pWnd==NULL)
{
MessageBox("error!");
return;
}
CRect rect;
pWnd->GetWindowRect(&rect);
ScreenToClient(&rect);
pWnd->MoveWindow(rect.left, rect.top, m_width, m_height, true);
CPaintDC pdc(pWnd);
::SetStretchBltMode(pdc, COLORONCOLOR);
//show image
BITMAPINFOHEADER *bmpinfo = (BITMAPINFOHEADER *)(imgBuf + sizeof(BITMAPFILEHEADER));
LPBITMAPINFO lpbmp = new BITMAPINFO;
ZeroMemory(lpbmp, sizeof(BITMAPINFO));
lpbmp->bmiHeader = *bmpinfo;
StretchDIBits(pdc.GetSafeHdc(), 0, 0, m_width, m_height, 0, 0, m_width, m_height, grayBuf, lpbmp, DIB_RGB_COLORS, SRCCOPY);
// Do not call CDialog::OnPaint() for painting messages
}
示例11: Win32_AspectBlt
static void Win32_AspectBlt( HDC hdc, win32BackBuffer_t *buffer, int width, int height ) {
if ( height == 0 ) {
height = 1;
}
if ( width == 0 ) {
width = 1;
}
float scale = 1.f;
int scaledWidth = buffer->width;
int scaledHeight = buffer->height;
if ( width < height ) {
scaledWidth = width;
scale = ( ( ( float ) width / ( float ) buffer->width ) + 0.5f );
scaledHeight = ( int ) ( ( scale * ( float ) buffer->height ) + 0.5f );
} else {
scaledHeight = height;
scale = ( ( ( float ) height / ( float ) buffer->height ) + 0.5f );
scaledWidth = ( int ) ( ( scale * ( float ) buffer->width ) + 0.5f );
}
int x = ( int ) ( ( ( width - scaledWidth ) / 2.f ) + 0.5f );
int y = ( int ) ( ( ( height - scaledHeight ) / 2.f ) + 0.5f );
PatBlt( hdc, 0, 0, width, height, WHITENESS );
PatBlt( hdc, x, y, scaledWidth, scaledHeight, BLACKNESS );
StretchDIBits( hdc,
x, y, scaledWidth, scaledHeight,
0, 0, buffer->width, buffer->height,
buffer->memory, &buffer->bitmapInfo,
DIB_RGB_COLORS, SRCCOPY );
/*PatBlt( hdc, 0, 0, x, y, WHITENESS );
PatBlt( hdc, x + scaledWidth, y + scaledHeight, width - x, height - y, WHITENESS );*/
}
示例12: WinProc
LRESULT CALLBACK WinProc(HWND hWnd, UINT Msg,
WPARAM wParam, LPARAM lParam)
{
switch (Msg)
{
case WM_CREATE:
break;
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;
case WM_PAINT:
{
HDC dc = GetDC(hWnd);
BITMAPINFO info;
ZeroMemory(&info, sizeof(BITMAPINFO));
info.bmiHeader.biBitCount = 24;
info.bmiHeader.biWidth = w;
info.bmiHeader.biHeight = h;
info.bmiHeader.biPlanes = 1;
info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
info.bmiHeader.biSizeImage = 0;
info.bmiHeader.biCompression = BI_RGB;
StretchDIBits(dc, 0, 0, w, h, 0, 0, w, h, buf, &info, DIB_RGB_COLORS, SRCCOPY);
ReleaseDC(hWnd, dc);
}
break;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
return 0;
}
示例13: max
void KImageCanvas::UponDrawPage(HDC hDC, const RECT * rcPaint, int width, int height, int pageno)
{
if ( (m_pPicture==NULL) && (m_pPicture->m_pBMI==NULL) )
return;
int sw = m_pPicture->GetWidth();
int sh = m_pPicture->GetHeight();
int dpix = sw * ONEINCH / width;
int dpiy = sh * ONEINCH / height;
int dpi = max(dpix, dpiy);
int dispwidth = sw * ONEINCH / dpi;
int dispheight = sh * ONEINCH / dpi;
SetStretchBltMode(hDC, STRETCH_HALFTONE);
int x = ( width- dispwidth)/2;
int y = (height-dispheight)/2;
if ( StretchJPEG(hDC, x, y, dispwidth, dispheight,
m_pPicture->m_pJPEG, m_pPicture->m_nJPEGSize, sw, sh ) )
return;
StretchDIBits(hDC, x, y, dispwidth, dispheight, 0, 0, sw, sh,
m_pPicture->m_pBits, m_pPicture->m_pBMI, DIB_RGB_COLORS, SRCCOPY);
}
示例14: sizeof
/* image is pre-rotated if landscape mode is selected */
void kGUIPrintJobWin::PrintSurface(kGUIDrawSurface *surface)
{
int sw,sh;
kGUIColor *bitmap;
BITMAPINFO bmpi;
bitmap=surface->GetSurfacePtrABS(0,0);
sw=surface->GetWidth();
sh=surface->GetHeight();
if(m_error==true) /* some error occured previously, abort */
return;
bmpi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpi.bmiHeader.biWidth = sw;
bmpi.bmiHeader.biHeight = -sh;
bmpi.bmiHeader.biPlanes = 1;
bmpi.bmiHeader.biBitCount = WINBPP;
bmpi.bmiHeader.biCompression = BI_RGB;
bmpi.bmiHeader.biSizeImage = 0;
bmpi.bmiHeader.biXPelsPerMeter = 0;
bmpi.bmiHeader.biYPelsPerMeter = 0;
bmpi.bmiHeader.biClrUsed = 0;
bmpi.bmiHeader.biClrImportant = 0;
StretchDIBits(m_pdc,
m_lmp,m_tmp, //upper left destination
m_dw,m_dh, //destination width/height
0, 0, // upper left of source
sw, sh, // source rectangle size
bitmap, &bmpi, DIB_RGB_COLORS,SRCCOPY);
}
示例15: GetDocument
void CDicomViewerView::DrawDicomImage(CDC* pDC)
{
CRect clientRect;
this->GetClientRect(&clientRect);
int nWidth=clientRect.Width(),nHeight=clientRect.Height();
CDC MemDC; //首先定义一个显示设备对象
CBitmap MemBitmap;//定义一个位图对象
//随后建立与屏幕显示兼容的内存显示设备
MemDC.CreateCompatibleDC(NULL);
//这时还不能绘图,因为没有地方画 ^_^
//下面建立一个与屏幕显示兼容的位图,至于位图的大小嘛,可以用窗口的大小
MemBitmap.CreateCompatibleBitmap(pDC,nWidth,nHeight);
//将位图选入到内存显示设备中
//只有选入了位图的内存显示设备才有地方绘图,画到指定的位图上
CBitmap *pOldBit=MemDC.SelectObject(&MemBitmap);
//先用背景色将位图清除干净,这里我用的是白色作为背景
//你也可以用自己应该用的颜色
MemDC.FillSolidRect(0,0,nWidth,nHeight,RGB(0,0,0));
CDicomViewerDoc* pDoc = GetDocument();
if(pDoc->m_pDicomImage != 0){
E_DecompressionColorSpaceConversion opt_decompCSconversion = EDC_photometricInterpretation;
E_UIDCreation opt_uidcreation = EUC_default;
E_PlanarConfiguration opt_planarconfig = EPC_default;
OFBool opt_verbose = OFFalse;
DJDecoderRegistration::registerCodecs(
opt_decompCSconversion,
opt_uidcreation,
opt_planarconfig,
opt_verbose);
//根据传输语法构造 DicomImage 从 fstart 帧开始一共 fcount 帧
DicomImage *pDicomImg = pDoc->m_pDicomImage;//new DicomImage(pDoc->m_pFilePathName);
//DicomImage *pNewDicomImg = pDicomImg->createScaledImage((const unsigned long)1024,1024);
LPBITMAPINFOHEADER m_lpBMIH = (LPBITMAPINFOHEADER) new char [sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256];
m_lpBMIH->biSize = sizeof(BITMAPINFOHEADER);
m_lpBMIH->biWidth = pDicomImg->getWidth();
m_lpBMIH->biHeight = pDicomImg->getHeight();
m_lpBMIH->biPlanes = 1;
m_lpBMIH->biBitCount = 24;
m_lpBMIH->biCompression = BI_RGB;
m_lpBMIH->biSizeImage = 0;
m_lpBMIH->biXPelsPerMeter = 0;
m_lpBMIH->biYPelsPerMeter = 0;
pDicomImg->setWindow(pDoc->m_dCurrentWindowCenter, pDoc->m_dCurrentWindowWidth);
//得到 DICOM文件第 frame 的 DIB数据(假设是 24 位的)
unsigned long bufSize = 0;
void* m_pDicomDibits;
bufSize =pDicomImg->createWindowsDIB(m_pDicomDibits, bufSize, 0, 24, 1, 1);
double originalX = (clientRect.Width() - m_lpBMIH->biWidth)/2;
double originalY = (clientRect.Height() - m_lpBMIH->biHeight)/2;
StretchDIBits (MemDC.GetSafeHdc(),originalX,originalY, m_lpBMIH->biWidth, m_lpBMIH ->biHeight,0,0,m_lpBMIH->biWidth,m_lpBMIH->biHeight,
m_pDicomDibits, (LPBITMAPINFO) m_lpBMIH,DIB_RGB_COLORS,SRCCOPY);
delete m_pDicomDibits;
}
//将内存中的图拷贝到屏幕上进行显示
pDC->BitBlt(0,0,nWidth,nHeight,&MemDC,0,0,SRCCOPY);
MemBitmap.DeleteObject();
MemDC.DeleteDC();
}