Jump to content

  • Log In with Google      Sign In   
  • Create Account


help loading a bitmap


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 01 December 1999 - 07:38 PM

ok! guys this a new big problem..
when not!
anyway I'm trying to load a bitmap with LoadImage but always it gives me the same problem with the memory when I try to create a surface. here's the code:
LPDIRECTDRAWSURFACE4 CargaBitmap(LPCTSTR file, int dw,int dh)
{
HBITMAP hbitmap;
BITMAP bitmap;
DDSURFACEDESC2 superf;
IDirectDrawSurface4* superficie;

//carga el bitmap
hbitmap = (HBITMAP) LoadImage(NULL,file,
IMAGE_BITMAP,//PUEDE SER UN CURSOR O UN ICONO
dw,dh,
LR_LOADFROMFILE | LR_CREATEDIBSECTION);//FLAGS PARA COMO CARGAR EL BITMAP
// coje el tamaño del bitmap
GetObject(hbitmap,sizeof(bitmap),&bitmap);
//crea una superficie para este bitmap
ZeroMemory(&superf,sizeof(superf));
superf.dwSize = sizeof(superf);
superf.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
superf.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
superf.dwWidth = bitmap.bmWidth;
superf.dwHeight = bitmap.bmHeight;
if(lpdd4->CreateSurface(&superf,&superficie,NULL)!=DD_OK)
return NULL;


CopiaBitmap(superficie,hbitmap,0,0,0,0);
DeleteObject(hbitmap);
return superficie;

}

HRESULT CopiaBitmap(LPDIRECTDRAWSURFACE4 superficie,HBITMAP hbitmap, int x, int y, int dx, int dy)
{
HDC hdcimagen;
HDC hdcsuperf;
BITMAP bitmap;
DDSURFACEDESC2 superf;
HRESULT hresult;
if (hbitmap == NULL | | superficie == NULL)
return E_FAIL;

superficie->Restore();
hdcimagen = CreateCompatibleDC(NULL);
if (!hdcimagen)
OutputDebugString("no pudo crear compatible\n");
SelectObject(hdcimagen,hbitmap);
GetObject(hbitmap,sizeof(bitmap),&bitmap);
dx = dx == 0 ? bitmap.bmWidth : dx;
dy = dy == 0 ? bitmap.bmHeight : dy;

superf.dwSize = sizeof(superf);
superf.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;
superficie->GetSurfaceDesc(&superf);

if ((hresult = superficie->GetDC(&hdcsuperf)) == DD_OK)
{
StretchBlt(hdcsuperf,0,0,superf.dwWidth,superf.dwHeight,hdcimagen,x,y,dx,dy,SRCCOPY);
superficie->ReleaseDC(hdcsuperf);
}
DeleteDC(hdcimagen);
return hresult;
}

sorry for the long code, the problem is always in the CreateSurface funtion.
I appreciate the way you guys help me in the past and will appreciate any help now

thanks
_José


Sponsor:

#2 NightShade   Members   -  Reputation: 122

Like
Likes
Like

Posted 29 November 1999 - 08:32 AM

The call to CreateSurface is failing? What HRESULT value does it return?
-ns

#3 magal   Members   -  Reputation: 122

Like
Likes
Like

Posted 01 December 1999 - 05:45 PM

Why don't you just use the normal bitmap loading function that comes with the DX7 SDK?

#4 WhiteHouse   Members   -  Reputation: 122

Like
Likes
Like

Posted 01 December 1999 - 07:38 PM

What error is it that you get? General Protection Fault, Compiler error, or something else?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS