surface question
this probably has been asked before but i have a surface of size 640x480 called lpdd1 now how do would i copy say a bitmap from lpdd1 the size of 64x64 onto surface2?
Well your not copying a bitmap, simply the pixels. You can do this using a standard blit operation. Do you want to copy only a 64x64 section of surface one or "shrink" the image down to surface2 which is 64x64? In either case setup source and destination RECT structures. Then make your call such as surface2->Blt(&DestRect,lpdd1,&SrcRect, DDBLT_WAIT, NULL);
This took me awhile too!
LPDIRECTDRAWSURFACE7 BitmapSurface(LPCTSTR filename, LPDIRECTDRAW7 lpLocalDD)
{
HDC hdc;
HBITMAP hbitmap;
LPDIRECTDRAWSURFACE7 surface;
//Load image to handle
hbitmap = (HBITMAP)LoadImage(NULL, filename, IMAGE_BITMAP, 0, 0,
LR_DEFAULTSIZE | LR_LOADFROMFILE);
//If fail return Null
if (!hbitmap)
{
return(NULL);
}//end if
//Get the bitmap''s size
BITMAP bitmap;
GetObject(hbitmap, sizeof(bitmap), &bitmap);
int surfwidth = bitmap.bmWidth;
int surfheight = bitmap.bmHeight;
HRESULT ddrval;
//Setup surface for creation
DDSURFACEDESC2 ddsd;
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
ddsd.dwWidth = surfwidth;
ddsd.dwHeight = surfheight;
ddrval = lpLocalDD->CreateSurface(&ddsd, &surface, NULL);
//If failed, clean up and return Null
if (ddrval != DD_OK)
{
DeleteObject(hbitmap);
return(NULL);
}
//Bit the temp DC to the surface''s dc and return the surface
else
{
surface->GetDC(&hdc);
HDC bitDC = CreateCompatibleDC(hdc);
SelectObject(bitDC, hbitmap);
BitBlt(hdc, 0, 0, surfwidth, surfheight, bitDC, 0, 0, SRCCOPY);
surface->ReleaseDC(hdc);
DeleteDC(bitDC);
}//end if
DeleteObject(hbitmap);
//Return success
return(surface);
}
//I assume DirectDraw7 is already setup and is lpDD
LPDIRECTDRAWSURFACE7 lpdd1;
lpdd1 = CreateBitmapSurface("bitmapfile.bmp", lpDD);
LPDIRECTDRAWSURFACE7 BitmapSurface(LPCTSTR filename, LPDIRECTDRAW7 lpLocalDD)
{
HDC hdc;
HBITMAP hbitmap;
LPDIRECTDRAWSURFACE7 surface;
//Load image to handle
hbitmap = (HBITMAP)LoadImage(NULL, filename, IMAGE_BITMAP, 0, 0,
LR_DEFAULTSIZE | LR_LOADFROMFILE);
//If fail return Null
if (!hbitmap)
{
return(NULL);
}//end if
//Get the bitmap''s size
BITMAP bitmap;
GetObject(hbitmap, sizeof(bitmap), &bitmap);
int surfwidth = bitmap.bmWidth;
int surfheight = bitmap.bmHeight;
HRESULT ddrval;
//Setup surface for creation
DDSURFACEDESC2 ddsd;
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
ddsd.dwWidth = surfwidth;
ddsd.dwHeight = surfheight;
ddrval = lpLocalDD->CreateSurface(&ddsd, &surface, NULL);
//If failed, clean up and return Null
if (ddrval != DD_OK)
{
DeleteObject(hbitmap);
return(NULL);
}
//Bit the temp DC to the surface''s dc and return the surface
else
{
surface->GetDC(&hdc);
HDC bitDC = CreateCompatibleDC(hdc);
SelectObject(bitDC, hbitmap);
BitBlt(hdc, 0, 0, surfwidth, surfheight, bitDC, 0, 0, SRCCOPY);
surface->ReleaseDC(hdc);
DeleteDC(bitDC);
}//end if
DeleteObject(hbitmap);
//Return success
return(surface);
}
//I assume DirectDraw7 is already setup and is lpDD
LPDIRECTDRAWSURFACE7 lpdd1;
lpdd1 = CreateBitmapSurface("bitmapfile.bmp", lpDD);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement