# Convert BMP - PNG/TGA

This topic is 5404 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Okay. I need an alpha channel because loading 64x64 textures with a colorkey takes 3 times the time as without. (as per my benchmarking) So, I'm trying to convert all of my textures (BMP) to PNG (or TGA) using D3DX.SaveTextureToFile (Dx8):
 d3dx.SaveTextureToFile App.Path & "\test1.tga", D3DXIFF_TGA, texture, PALLETEENTRY
When texture is correctly loaded, BMP texture. Which gives me the invalid data error. Which means the problem could lie in 2 placed:
• in the PALLETEENTRY (in which all values are default)
• can't convert textures with this function.
I suspect its the latter (since I can save it as a BMP fine), and that I'll probably have to stick all the textures onto a surface, then save the surface to a file. My problem is, I can't find this function in either the SDK or the MSDN (must be in there somewhere!) Or it might be due to the paletteentry. I'm not sure which. Which is why I'm posting here... [headshake] [lol]

##### Share on other sites
Parameters

pDestFile
[in] Pointer to a string that specifies the file name of the source image. If the compiler settings require Unicode, the data type LPCTSTR resolves to LPCWSTR. Otherwise, the string data type resolves to LPCSTR. See Remarks.
DestFormat
[in] D3DXIMAGE_FILEFORMAT specifying the file format to use when saving. This function supports saving to all D3DXIMAGE_FILEFORMAT formats except Portable Pixmap (.ppm) and Targa/Truevision Graphics Adapter (.tga).
pSrcTexture
[in] Pointer to IDirect3DBaseTexture9 interface, containing the texture to be saved.
pSrcPalette
[in] Pointer to a PALETTEENTRY structure containing a palette of 256 colors. This parameter can be NULL.

Quoted from the C++ SDK doc.

##### Share on other sites
I tried to save to .TGA before and discovered that DX won't do it, even though it is one of the options.

It didn't bug me too much because it took only a minute or two to record a script in Photoshop that would convert between formats, but I wonder why they support reading but not writing this format.

##### Share on other sites
Thanks - that explains why the TGA won't work. [cool]

(somehow it wasn't in my C++ SDK either.. hmm..)

Any reason for the PNG? I'll try setting the paletteentry = null and see if that works. [sick]

##### Share on other sites
Dude, since BMPv4 there BMP files have had alpha. I have a bmp loader that loads BMP files up to version 5 (the only thing it doesn't do is the JPEG or PNG styles of compression, and yes they are available with the current version of BMP).

I have a loader written and photoshop 7.0 saves with alpha in both 16 and 32 bit BI_BITFIELDS formats.

##### Share on other sites
The other thing I need is better image compression. BMP isn't exactly what you'd call... efficient. Especially when you have 100MB of them to load, it's much faster to access something like JPGs from the HD. Just trying to kill 2 birds with one stone...

I'll look into BMP alpha channels, though. Thanks.

##### Share on other sites
Well, fixed my converting procedure to change everything into bitmaps, since a test showed all the areas alphaed out by a colorkey to be (or looked like) transparent black. (and the fact that the textures are 96x96 and I put them down as 128x128 didn't fare too well...)

But it wasn't transparent black. It was just black (my own fault). So, apparently, Dx8 won't let me save alpha values. Huh.

Anyone else know any other ways to set a certain color to alpha in lots of bitmaps? Because it appears that Dx is eating my pictures alive... I'm thinking of just making them all JPGs, to cut down on their size -> faster loading.

Thanks for your help guys. Ratings++ to all!

Damn... I hate not being able to multithread... [crying]

##### Share on other sites
Have you tried PNGs? They are supported by D3DX and have alpha channels as well as resonable compression ratios.

For faster loading consider DXT1 and DXT5 formats - the DXSDK summer update contains a Photoshop/PSP plugin, too.
[/edit]

##### Share on other sites
I have tried to save my textures to PNG, but for some reason it gives me an Invalid Data error. Hmm... This may be due to the fact that I had the wrong texture sizes (thought 96x96 were 128x128), which may be the cause. I'll fix this tommorrow and see if it works after that. I'll look into the DXT1 and DXT5 formats too. Thanks!

I feel stupider after each post. Soon, my IQ will be < 0... [lol]

• 17
• 10
• 21
• 16
• 9