Skip to main content
gamedev.net
🔒 Locked

Bitmap Extraction

Started by Omega147 5 replies 900+ views
Original Post
Omega147
Omega147
Basically what I''m asking about is sprites (I think). What I want to do is take a bitmap that''s, oh say, 100x100 pixels, and then only display the pixels within a 50x50 area. If you''re wondering what I''m trying to do, I''m trying to do animation. You know, display one frame, then the next, and so forth. Anyway, to sum it up, I want to extract an area from a bitmap and only display the extracted area onto whatever surface I desire. Using DirectX 8 if that helps at all. Thanks.
niyaw
niyaw
load the entire file into one texture, and change texture coorinates depending on which part of it you want to see. for instance, use 0,0-0.5,0.5 to show top-left quarter of it.
Omega147
Omega147
I believe I have already tried that, and what I got was my bitmap getting stretched and distorted.

Unless I''m doing that wrong... :/
Nytegard
Nytegard
Omega, what niyaw is correct.

Load the entire bitmap into a texture.

Set the texture position accordingly.

Here''s a sample:


  
struct CUSTOMVERTEX
{
D3DVECTOR vector;
DWORD color; // The vertex color

FLOAT tu;
FLOAT tv;
};

CUSTOMVERTEX back[] =
{
{-0.75f,0.0f,0.5f,0xffffffff,0.0f,0.5f,},
{-0.75f,0.5f,0.5f,0xffffffff,0.0f,0.0f,},
{0.75f,0.5f,0.5f,0xffffffff,0.5f,0.0f,},
{0.75f,0.0f,0.5f,0xffffffff,0.5f,0.5f,},
};


Load that into the device, and it should show 50x50. Of course, the vertex design is all up to you.
Omega147
Omega147
Hmm... I noticed your D3DVECTOR command, and well, I haven''t jumped into Direct3D just yet. I''m still working with 2D animation.

I''ll rephrase what I''m after:

Okay, I''ve created a surface for my picture and I''ve also loaded my image, which we''ll call "image.bmp," onto a LPDIRECTDRAWSURFACE, which we''ll name "lpddsimage."

To display my image, I do this:

SetRect(&image.rect,image.x,image.y,image.x+image.w,image.y+image.h);
lpddsback->Blt(ℑ,lpddsimage,NULL,DDBLT_WAIT|DDBLT_KEYSRC,&bltfx);

And basically that''s what I have. And yes, I have tried changing the "NULL" in my Blt(); function to be the destination rectangle and what-not, but that didn''t quite work. It ended up resizing my entire image (stretching and distorting it).

As I said above, all I want to do is display a portion of my bitmap without it becoming mutilated.

I hope that kind of explains my situation better.
hammerstein_02
hammerstein_02
Destination rect is where on the destination surface you wish to place the image. This needs to be the x,y where you want to place it, and the x+width, y+height. If you were putting the image into a rect larger, it will stretch.

To get the frames from your surface you need to keep track of which frame you are in then do something like;

RECT myRect = {frame*width,0,(frame*width) + width,height};
RECT dstRect = {x,y,x+width,y+width};
(Presuming you store your image like:

-----------------
| | | | |
-----------------

)

where width and height are the preset variables (50 and 50) and frame is 0-3.

Then using Blt you can..

lpddsback->Blt(myRect,lpddsimage,dstRect,DDBLT_WAIT | DDBLT_KEYSRC, &bltfx);

Thats roughly it, it might take a bit of playing around with but thats similar to what I do. E-mail me if you need any more assistance.
LordLethis
LordLethis
I''d recommend to use BltFast, it''s faster, but can''t clip (i.e. your image won''t show up if any part is outside the screen, so you have to do that yourself). And if you use Blt, make sure the dest and source rect are the same size.




Those who do not love don''t live.




[MSDN|Google|Bloodshed|My lousy page|email.me]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.