Jump to content
  • Advertisement
Sign in to follow this  
modulen

Editing and Saving Bitmaps

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

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
Advertisement
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?

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
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.

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
This site is full of info about file formats.
I think it's the best.

The Programmer's File Format Collection - http://www.wotsit.org

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!