#### Archived

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

# bitmap loading/blting troubles

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

Ok, i apologize for this extremely vague question up front... I made a little 2d game engine using directx, one problem it has is that if I try to load bitmaps that are not 640x480, or a multiple of 640x480, and then blt them to the screen, they look all messed up, This also happens if i load a 640x480 bitmap and then try to blt it to a space that is not a multiple of 640x480. any ideas on what could be causing this? thanks

#### Share this post

##### Share on other sites
try making thebitmap bigger by one or two pixels

PROGAMERS

#### Share this post

##### Share on other sites
do you mean just change the actual .bmp and then leave my code the same? or change the size I load into my program, Ive played around with it for a few minutes and it doesnt seem to be helping.

#### Share this post

##### Share on other sites
How are you blitting and how does it look messed up? Is it simply stretching it across the whole screen or do you, literally, end up with garbage?

#### Share this post

##### Share on other sites
Are you using the DirectDraw Blitting routines? (Blt and BltFast)?? If you are writing the blit functions yourself, make sure you are locking the surfaces (and unlocking) and that you take into account the surface pitch (width). The pitch wont always be the same as your screen width. I think for 640x480 it is 640 pixels. This may be your problem.

Denny.

#### Share this post

##### Share on other sites
i am trying to draw a bitmap in the form of a rectangle, 100x250 pixels, it looks fine, except the bottom 50 pixels or so just looks like static

//here are the main functions that i am usingstruct pic{ int x; int y; int width; int height; LPDIRECTDRAWSURFACE img;};bool draw2(LPDIRECTDRAWSURFACE target, pic *mypic, int w, int h){ //formated drawing to scale RECT tar; tar.top = mypic->y; tar.left = mypic->x; tar.bottom = tar.top + h; tar.right = tar.left + w; RECT src; src.left = 0; src.top =0; src.right = mypic->width - 3; src.bottom = mypic->height - 3; target->Blt(&tar, mypic->img, &src, DDBLT_WAIT | DDBLT_KEYSRC, NULL); return true;}bool load(pic *mypic, char *filename){ //for some reason this only loads well //with bmps of easy sizes //you kinda have to guess what an easy size is //factors of 640 x 480 seem to work well BITMAP_FILE bmpfile; if( Load_Bitmap_File(&bmpfile, filename) == 0) return false; //pallette lpddpal->SetEntries(0,0,256, bmpfile.palette);// mypic->img->SetPalette(lpddpal); memset(&ddsd,0,sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); (mypic->img)->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); video_buffer = (UCHAR *)ddsd.lpSurface; memset(video_buffer, 0, mypic->height * mypic->width); memcpy(video_buffer, bmpfile.buffer, mypic->height * mypic->width); (mypic->img)->Unlock(video_buffer); Unload_Bitmap_File(&bmpfile); return true;}bool setup(LPDIRECTDRAW main, pic *mypic, int w, int h){ //setup the pic //initialize vars and such //mypic = the pic to set up //w = width //h = height mypic->height = h; mypic->width = w; mypic->x = 0; mypic->y = 0; memset(&ddsd,0,sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; ddsd.dwHeight = h; ddsd.dwWidth = w; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; if(main->CreateSurface(&ddsd, &(mypic->img), NULL) != DD_OK) return false; DDCOLORKEY col; col.dwColorSpaceHighValue=0; col.dwColorSpaceLowValue=0; (mypic->img)->SetColorKey(DDCKEY_SRCBLT, &col); return true;}

#### Share this post

##### Share on other sites
I had this sort of trouble and I eventually figured out that this would only happen to bitmaps that didn''t have a length and width of factors of 8. I was using 16-bit color, and I assume I had these problems because I was copying the image data in chunks of 8 bits and so, if I had any image that did not have sides a factor of 8, then I would be copying some extra (or lack of) information at the end of each line, thus causing my image to be slanted, or completely full of garbage.

Now, I''m not sure if that''s entirely the reason to my troubles, but it''s something like that. Anyways, I just fixed it by always making my bitmaps have dimensions that are %8.

*shrug*

HellspawnXIII
"There''s a lot of stuff in this world that needs stepping on."

#### Share this post

##### Share on other sites
Your problem is that you are using the width of your image to do the blitting. If the surface resides in video memory there is no gaurantee that the width of the surface is the same as the width of the bitmap. What you have to use is ddsd.lPitch instead of mypic->width when copying the memory from one location to the other. For the blitting rectangles you should use the width though.

#### Share this post

##### Share on other sites
For the bitmap loading problems with uneven width.
BMP lines are padded to 32bits. So if the width of a line (in bytes) is not divisible by 4 it fill be filled with zeroes until it is (only inside the file, do not add those to your image in memory).

#### Share this post

##### Share on other sites
Try reading this. Your problem is the padding (as the people before me said). That post may help you understand it better. Read the whole thing.

• ### Forum Statistics

• Total Topics
628644
• Total Posts
2984007

• 9
• 9
• 10
• 21
• 20