Jump to content
  • Advertisement

Archived

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

Gilzu

DirectDraw put bmp file on screen

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
still trublesome...

  
HDC hdcImage;
HDC hdc;

//getting the back surface device context

pddsBack->GetDC(&hdc);

// create a compatible one to put the image on

hdcImage = CreateCompatibleDC(hdc);

// now HBITMAP->HDC

SelectObject(hdcImage, bitmap);

// something that _should''ve_ been on the screen

BitBlt(hdc, x, y, width, height, hdcImage, 1, 1, SRCCOPY);

// release after usage

pddsBack->ReleaseDC(hdc);
DeleteDC(hdcImage);

//Flip to see results that dont come

pddsPrimary->Flip(NULL,0)


help?

Share this post


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

10x alot anyway!
Gil

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!