views:

617

answers:

3

I am drawing bitmap images on graphics object using DrawImage method But the Images are in large number so it is taking too much time for Drawing. I have read in this forum that using StretchDIBits takes less time for Drawing. I am scaling the image by calling Drawimage but i want any other efficent method. I have a Vector of Bitmap* & i want to draw each Bitmap on graphics.

HDC orghDC = graphics.GetHDC();
CDC *dc = CDC::FromHandle(orghDC);

m_vImgFrames is image vector containg Bitmap*. I have taken HBITMAP from Bitmap*.

HBITMAP hBitmap;
m_vImgFrames[0]->GetHBITMAP(Color(255,0,0),&hBitmap);

Using this HBITMAP i want to draw on orghDC & finally on graphics. So I want to know how StretchDIBits can be used for scaling the Bitmap and finally draw on Graphics Object.

I am new to this forum.Any ideas or code can be helpful

+1  A: 

Instead of using StretchDIBits, why not use the GDI+ API directly to scale the bitmap?:

CRect rc( 0, 0, 20, 30 );

graphics.DrawImage( (Image*)m_vImgFrames[0], 
    rc.left, rc.top, rc.Width(), rc.Height() );
Alan
VideoDev
i was going to comment on your question, but VideoDev beat me to it. You don't want to use DrawImage because it is very slow.
Ian Boyd
A: 

hay can u tell me what option u have used for this....

because this may be useful for my code...

I want to copy contents drawn by using CDC object on Graphics object.

sheetal
A: 

To use StretchDIBits with Gdiplus::Bitmap you could do the following:

// get HBITMAP
HBITMAP hBitmap;
m_vImgFrames[0]->GetHBITMAP( Gdiplus::Color(), &hBitmap );
// get bits and additional info
BITMAP bmp = {};
::GetObject( hBitmap, sizeof(bmp), &bmp );
// prepare BITMAPINFO
BITMAPINFO bminfo = {};
bminfo.bmiHeader.biSize = sizeof( BITMAPINFO );
bminfo.bmiHeader.biWidth = bmp.bmWidth;
bminfo.bmiHeader.biHeight = bmp.bmHeight;
bminfo.bmiHeader.biBitCount = bmp.bmBitsPixel;
bminfo.bmiHeader.biCompression = BI_RGB;
bminfo.bmiHeader.biPlanes = bmp.bmPlanes;
bminfo.bmiHeader.biSizeImage = bmp.bmWidthBytes*bmp.bmHeight*4; // 4 stands for 32bpp
// select stretch mode
::SetStretchBltMode( HALFTONE );
// draw
::StretchDIBits( hDC, 0, 0, new_cx, new_cy, 0, 0,
  m_vImgFrames[0]->GetWidth(), m_vImgFrames[0]->GetHeight(), 
  bmp.bmBits, &bminfo, DIB_RGB_COLORS, SRCCOPY );

But this doesn't looks much faster on my machine than simple Graphics::DrawImage.

Kirill V. Lyadvinsky