#### Archived

This topic is now archived and is closed to further replies.

# DirectDraw put bmp file on screen

This topic is 6174 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

k, i''m trying to show a content of 24bit bmp file on the screen. so far i''ve:
  HBITMAP bitmap; FILE *bmpfile; bmpfile = fopen(Bitmap_Filename,"r"); BITMAPFILEHEADER bmpheader; fread(&bmpheader, sizeof(BITMAPFILEHEADER), 1, bmpfile); BITMAPINFOHEADER bmpinfoheader; fread(&bmpinfoheader, sizeof(BITMAPINFOHEADER), 1, bmpfile); bmp = new char[bmpinfoheader.biSizeImage]; fread(bmp, bmpinfoheader.biSizeImage, 1, bmpfile); bitmap = CreateBitmap(bmpinfoheader.biWidth, bmpinfoheader.biHeight, bmpinfoheader.biPlanes, 24, bmp); fclose(bmpfile); 
assuming thats true (again, for 24bpp bitmap) cause it works, but i cant see the pic yet because i cant put it on the screen. or at least i dunno how. so if i have the bitmap in a HBITMAP form in the memory, how do i put HBITMAP format on a HDC of the back buffer?

##### Share on other sites
Once you have your HBITMAP, you need to get the DC from the surface you want to draw your bitmap to. For example, say you have an offscreen surface, called lpddsBitmap, just waiting to be drawn on, you could do the following

  lpddsBitmap->GetDC( &hDC );

Now hDC is the Device context for the surface lpddsBitmap. Now you can use the function StretchBlt() to draw your image onto your surface. And when you are finished, be sure to release the DC on the surface. If you don''t, the surface will remain locked, and you will run into some errors when flipping. Take a look at StretchBlt in the SDK Docs. Hope this helps.

-----------------------------
kevin@mayday-anime.com
http://dainteractive.mayday-anime.com

##### Share on other sites
still trublesome...

  HDC hdcImage;HDC hdc;//getting the back surface device contextpddsBack->GetDC(&hdc); // create a compatible one to put the image onhdcImage = CreateCompatibleDC(hdc); // now HBITMAP->HDCSelectObject(hdcImage, bitmap); // something that _should''ve_ been on the screen BitBlt(hdc, x, y, width, height, hdcImage, 1, 1, SRCCOPY);// release after usagepddsBack->ReleaseDC(hdc); DeleteDC(hdcImage); //Flip to see results that dont comepddsPrimary->Flip(NULL,0)

help?

##### Share on other sites
it seems that i was actually right.
found the mistake, width and height were wrong.

10x alot anyway!
Gil

##### Share on other sites
Just for information purposes, here is my code

  // Stretch the bitmap to cover this surface if( FAILED( hr = g_lpddsScene->GetDC( &hDC ) ) ) return hr; // Draw our image StretchBlt( hDC, 0, 0, g_ddsd.dwWidth, g_ddsd.dwHeight, hDCImage, 0, 0, dwWidth, dwHeight, SRCCOPY ); if( FAILED( hr = g_lpddsScene->ReleaseDC( hDC ) ) ) return hr;

-----------------------------
kevin@mayday-anime.com
http://dainteractive.mayday-anime.com

• 38
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631362
• Total Posts
2999577
×