• Advertisement

Archived

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

bitmap image getting strectched

This topic is 5421 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

For some reason, when I load a bitmap into an offscreen buffer, the image is getting stretched. I''m using code pretty similar to that used in Game Genesis article 6, but I''ll post it if someone wants. I''m curious what kinds of things could cause a bitmap to get stretched when I''m not explicitly telling it to stretch it (I think)?

Share this post


Link to post
Share on other sites
Advertisement
Well, I am working in 32-bit, but I tried loading the bitmap in 8-bit, and it did the same thing. Here's the code I'm using:


    
typedef struct BITMAP_FILE_TYP_24
{
BITMAPFILEHEADER bitmapfileheader;
BITMAPINFOHEADER bitmapinfoheader;
LPDIRECTDRAWSURFACE7 lpddsbuffer;
BITMAP bmp;
} BITMAP_FILE_24, *BITMAP_FILE_PTR_24;


int Load24bitBitmap(BITMAP_FILE_PTR_24 bitmap, char *filename)
{
OFSTRUCT file_data; // the file data information

int file_handle;
DDSURFACEDESC2 ddsd;
HRESULT hr;

DDRAW_INIT_STRUCT(ddsd);

// open the file if it exists

if ((file_handle = OpenFile(filename,&file_data,OF_READ))==-1)
return(0);

_lread(file_handle, &bitmap->bitmapfileheader,sizeof(BITMAPFILEHEADER));
_lread(file_handle, &bitmap->bitmapinfoheader,sizeof(BITMAPINFOHEADER));

_lclose(file_handle);

bitmap->lpddsbuffer = CreateOffscreenSurface(bitmap->bitmapinfoheader.biWidth,
bitmap->bitmapinfoheader.biHeight);

HBITMAP hbitmap;
HDC hSrcDC;
HDC hDestDC;


if ((hbitmap = (HBITMAP) LoadImage(NULL, filename,
IMAGE_BITMAP, bitmap->bitmapinfoheader.biWidth,
bitmap->bitmapinfoheader.biHeight,
LR_LOADFROMFILE | LR_CREATEDIBSECTION)) == NULL)
{
return(0);
}

if ((hSrcDC = CreateCompatibleDC(NULL)) == NULL)
{
return(0);
}

if (SelectObject(hSrcDC, hbitmap) == NULL)
{
DeleteDC(hSrcDC);
return(0);
}

if (GetObject(hbitmap, sizeof(BITMAP), &bitmap->bmp) == 0)
{
DeleteDC(hSrcDC);
return(0);
}

if (FAILED(bitmap->lpddsbuffer->GetDC(&hDestDC)))
{
DeleteDC(hSrcDC);
return(0);
}

if (BitBlt(hDestDC, 0, 0,
bitmap->bmp.bmWidth, bitmap->bmp.bmHeight,
hSrcDC, 0, 0, SRCCOPY) == NULL)
{
DeleteDC(hSrcDC);
bitmap->lpddsbuffer->ReleaseDC(hDestDC);
return(0);
}


DeleteDC(hSrcDC);
bitmap->lpddsbuffer->ReleaseDC(hDestDC);

return(1);
}


I know some of the stuff is redundant. I probably don't need to have both a BITMAP variable and the BITMAPFILEHEADER and BITMAPINFOHEADER variables in the same struct, but I don't think it's causing a problem right now, so I left it.

[edited by - Igrum on March 17, 2003 12:44:45 PM]

Share this post


Link to post
Share on other sites

  • Advertisement