Archived

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

Problem loading/displaying bitmaps.

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

Here see if this works for you.

yourbuffer[x + y*(lpitch >> 1)] = pixel or whatever.

Let me know if that worked. Good luck, friz

------------------
Still Learning...

[This message has been edited by frizb (edited November 19, 1999).]

Share this post


Link to post
Share on other sites
*sigh* seems like I keep interfering with bitmap problems *LOL*. I don't mind. I love it.

Okay, here is what I think you are doing, or at least a small part of it.

1) You have got a directdraw surface with the height and width of the image you are want to load.

2) You open the image.

3) Lock the surface, read in the BGR format pixels into unsigned char. Convert it to a 16 bit (either 1555 or 565....the one showed is for 1555)

unsigned short color = (unsigned short)( ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3) );

And then you put this value onto the directrawsurface.

Shouldn't be too difficult.

------------------
Dance with me......

Share this post


Link to post
Share on other sites
Oh and I forgot to say that you have to add what is left to the directdrawsurface pointer

so....add the lPitch - DDSURFWidth to the surfacepointer.....

And keep in mind that a 24 bits bitmap is saved in reverse order (bottom to top) so you need to subtract 2 times the width each time.

------------------
Dance with me......

Share this post


Link to post
Share on other sites
Actually, that's not exactly what Im doing, this is what I do... (I made my class Bitmap that handles BMPs)

Bitmap image;
image.LoadBitmap("24BitGraphic.bmp");

so now the BMP is loaded and converted to a 16bit BMP stored in image.buffer

so now I lock the back surface (Im not using offsurfaces now, cause Im only interested in displaying the bitmap correctly at the time, I'll make it work better once it's actually working), after I lock the back surface I do something like this:

for (int i=0; i < (2*image.Height)-1; i++)
{
memcpy(SurfacePtr, image.buffer, image.Width);
SurfacePtr += 640;
image.buffer += image.Width;
}

and what that does is display HALF of the bitmap where it's supposed to be, then a gap between that and the other half...

However, if I do this:

for (int i=0; i < (2*image.Height)-1; i++)
{
memcpy(SurfacePtr, image.buffer, image.Width*2);
SurfacePtr += 640;
image.buffer += image.Width*2;
}

it displays the bitmap correctly on the top left corner, BUT, it displays a second copy of the bitmap after the gap, only the second copy of the bitmap is distorted (second half is drawn first, first half last)..

I know the bitmap loading/conversion part is working, cause if I write the converted bitmap to a file, it'll work fine when I open it with PSP. So Im thinking my problem is in the actual blitting of the image (the colors work fine, btw).

Thanks!

------------------
VisualLR
visuallr@netscape.net
http://www.geocities.com/SiliconValley/6276

Share this post


Link to post
Share on other sites
Hey, I wrote a bitmap loader today, but I had a small problem... see, I loaded a 24bit bmp and converted it to a 16bit one, the loading and conversion work fine, and to test it I wrote the converted bitmap to a file, when I open it with PSP or whatever it looks fine. BUT, when I draw it on a surface I have problems, cause I loaded the converted 16bit bitmap into a buffer that's 2*Width*Height in size, so, if I try to draw the bitmap onto a surface I get on one side the actual bitmap looking good, but right next to it I got another copy of the bitmap that's distorted.. so what I need to know is if I have to reduce the size of the converted buffer to Width*Height for it to actually work, or if it's just my blitter that's wrong... let me know if you need more details, cause I feel like I didnt make much sense if at all...

------------------
VisualLR
visuallr@netscape.net
http://www.geocities.com/SiliconValley/6276

Share this post


Link to post
Share on other sites