Editing and Saving Bitmaps

Started by
9 comments, last by evillive2 19 years, 8 months ago
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]
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?
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
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.
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. :)
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.
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.
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. ;)
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!
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
Alfred Reinold Baudisch[Game Development Student] [MAC lover] [Ruby, Ruby on Rails and PHP developer] [Twitter]

This topic is closed to new replies.

Advertisement