Sign in to follow this  
modulen

Editing and Saving Bitmaps

Recommended Posts

I feel like this should be easier than I am finding it to be, so I am posting here to see if anyone can help. :) I've searched through the forums and havn't found anything directly on point. I am trying to read in a bitmap file that is (say) 640x480 and break it into two other bitmap files (512x512 each). It is a bitmap of 60x60 tiles and I want to copy half the tiles into bitmapfile1, padd the space that isn't filled, and the save that bitmap. I then want to copy the other half of the tiles into a second bitmap file, padd the extra space with filler, and then save that bitmap file. These are 8 bit bitmaps. I think what I'm missing is how to copy the data the data from one bitmap to a new bitmap I've created in memory and then to save it to a file. I see a lot of tutorials that seem to have pieces of this information, but nothing clear. Naturally I can sort of do this outside the program in Paint Shop Pro, but I'd rather do it in the program. Thanks for anyone that can help! EDIT: I am equally happy to buy a book on this topic if someone can recommend one to buy. :) [Edited by - modulen on August 5, 2004 10:04:16 AM]

Share this post


Link to post
Share on other sites
Here is the bitmap file format document I used to write my bitmap saver. It should help you with loading and saving. If you can't figure it out, I can give you my hacked-up saving code (I used the Win32 functions for loading).
Then for transferring between images, you should be able to select you bitmaps into a DC for each, and BitBlt() between them.

- Pete

Share this post


Link to post
Share on other sites
Quote:
Original post by Nuget5555
You could code the bitmap creation and saving yourself but it would probably be easier to do with the help of an API. Are you using Direct X?


This makes sense to me. I am using DirectX8.1 currently.

Share this post


Link to post
Share on other sites
Quote:
Original post by Pete_
Here is the bitmap file format document I used to write my bitmap saver. It should help you with loading and saving. If you can't figure it out, I can give you my hacked-up saving code (I used the Win32 functions for loading).
Then for transferring between images, you should be able to select you bitmaps into a DC for each, and BitBlt() between them.

- Pete


Thanks, Pete, I'll check into that shortly. :)

Share this post


Link to post
Share on other sites
Here are the steps you will need to take in order, with brief explanations:

D3DXCreateTextureFromFileEx()
Use this function to load your main texture. You will have to set the USAGE parameter to D3DUSAGE_DYNAMIC and the POOL parameter to D3DPOOL_DEFAULT. You are doing this because you will need to 'lock' the texture later to grab out it's data.

IDirect3DDevice8::CreateTexture()
Use this to create the 4 256x256 textures

IDirect3DTexture8::LockRect()
Use this to 'Lock' the 4 256x256 textures as well as the big texture. You have to 'lock' the texture because you can't edit the texture memory on the card directly.

Now copy the memory from the main texture into each of the 4 smaller textures.

IDirect3DTexutre8::UnlockRect()
Use this to 'Unlock' your textures after you have copied the data over. 'Unlocking' the texture will copy the texture to the graphics card, making it ready to render.

D3DXSaveTextureToFile()
Use this to save your 4 created textures to files.

Tada! Let me know if are having problems or need something explained better.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Nuget5555
Here are the steps you will need to take in order, with brief explanations:

D3DXCreateTextureFromFileEx()
Use this function to load your main texture. You will have to set the USAGE parameter to D3DUSAGE_DYNAMIC and the POOL parameter to D3DPOOL_DEFAULT. You are doing this because you will need to 'lock' the texture later to grab out it's data.

IDirect3DDevice8::CreateTexture()
Use this to create the 4 256x256 textures

IDirect3DTexture8::LockRect()
Use this to 'Lock' the 4 256x256 textures as well as the big texture. You have to 'lock' the texture because you can't edit the texture memory on the card directly.

Now copy the memory from the main texture into each of the 4 smaller textures.

IDirect3DTexutre8::UnlockRect()
Use this to 'Unlock' your textures after you have copied the data over. 'Unlocking' the texture will copy the texture to the graphics card, making it ready to render.

D3DXSaveTextureToFile()
Use this to save your 4 created textures to files.

Tada! Let me know if are having problems or need something explained better.


Thanks Nuget! I think this will work well. The one thing I think I'm left trying to figure out is that my initial file isn't in a power of 2 foramt (being 640x480), so I think I may need a step before your first one?

Thanks! I'll work on it. ;)

Share this post


Link to post
Share on other sites
Quote:
Original post by Rickmeister
Personally I use the FreeImage lib for all image handling in my projects. Really simple to use and it even loads/saves image formats I've never heard of [smile]

It supports bmp,jpg,png and tga - wich I guess is the most common formats for game graphics.


I'll look into this as well. Thanks!

Share this post


Link to post
Share on other sites
Were you using SDL this would be a simple matter but because you are using DirectX it becomes a little more difficult. Not sure if you are using d3d8 or DirectDraw but I find this kind of think really simple in DDraw. What you want to do is Load the bitmap onto a surface and create 2 blank surfaces of the size you want. Then individually blit the tiles you want onto each empty surface and then use the many tutorials (I suggest Big Sassy's bitmap tutorials on Gamedev here) to figure out how to save the 2 surfaces to disk.

Were you using SDL it is kind of the same thing but SDL has a SDL_SaveBMP function that will save a surface as a bitmap for you which is the difficult part anyway. I would say if this is just a utility then try doing it in SDL and see how it turns out. The worst thing that can happen is that you have a tool you can use for other games.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this