C++读写Tga文件

// tga.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include 
#include 
#include 
using namespace std;

#define RGB2INT(r,g,b) (r*256*256 + g*256 + b)

void SaveTGA( const char *filename, DWORD width, DWORD height, const byte *data )
{
	FILE *savefile = fopen(filename, "wb");

	byte type_header[12] =  {0,0,2,0,0,0,0,0,0,0,0,0};
	fwrite(  type_header,12*sizeof( byte ),1,savefile );

	byte header[6];
	header[0] = width % 256;
	header[1] = width / 256;
	header[2] = height % 256;
	header[3] = height / 256;
	header[4] = 32;
	header[5] = 8;

	fwrite( header, 6*sizeof( byte ),1,savefile );

	unsigned int image_size= 4*width*height;
	byte * invert_data = new byte [image_size];
	memset( invert_data,0,image_size*sizeof( byte ) );

	for( unsigned int i=0; i


适用于32位色的无压缩tga文件。

你可能感兴趣的:(C++)