-
大小: 110KB文件類型: .zip金幣: 2下載: 1 次發布日期: 2021-06-18
- 語言: C/C++
- 標簽: RayTracing??
資源簡介
TGA格式(Tagged Graphics)是由美國Truevision公司為其顯示卡開發的一種圖像文件格式,文件后綴為".tga",已被國際上的圖形、圖像工業所接受。 TGA的結構比較簡單,屬于一種圖形、圖像數據的通用格式,在多媒體領域有很大影響,是計算機生成圖像向電視轉換的一種首選格式。 TGA圖像格式最大的特點是可以做出不規則形狀的圖形、圖像文件,一般圖形、圖像文件都為四方形,若需要有圓形、菱形甚至是縷空的圖像文件時,TGA可就派上用場了! TGA格式支持壓縮,使用不失真的壓縮算法。 TGA格式是Truevision公司設計并負責解釋的圖像格式。TGA也包含了多種變體,TGA文件的第三個字節用來區別不是TGA的文件。

代碼片段和文件信息
#include
#include
using?namespace?std;
#define?WIDTH_RES?640
#define?HEIGHT_RES?480
unsigned?char?*PB?=?new?unsigned?char[WIDTH_RES*HEIGHT_RES*3];
void?WriteTGA();//生成文件
int?main()
{
int?Index?=?0;?
float?r?=?0?g?=?0?b?=?0;
for?(int?y?=?0;?y? {
if?(y?==?0)?cout?<“??0%?has?completed...“?< if?(y?==?(int)(HEIGHT_RES?*?0.4))?cout?<“?25%?has?completed...“?< if?(y?==?(int)(HEIGHT_RES?*?0.5))?cout?<“?50%?has?completed...“?< if?(y?==?(int)(HEIGHT_RES?*?0.75))?cout?<“?75%?has?completed...“?< if?(y?==?(int)(HEIGHT_RES?-?1))?cout?<“100%?has?completed...“?<
r?=?y*256?/?HEIGHT_RES;
for?(int?x?=?0;?x? {
g?=?x?*?256?/?WIDTH_RES;
PB[Index?+?0]?=?(int)b;
PB[Index?+?1]?=?(int)g;
PB[Index?+?2]?=?(int)r;//以BGR形式存儲
}
}
WriteTGA();//生成文件
if?(PB)?delete[]?PB;
return?0;
}
void?WriteTGA()//生成文件
{
FILE?*pFile?=?0;
unsigned?char?tgaHeader[12]?=?{?0?0?2?0?0?0?0?0?0?0?0?0?};//文件頭
unsigned?char?header[6];//前六位
unsigned?char?bits?=?24;//24位
int?colorMode?=?3;//RGB
header[0]?=?WIDTH_RES?%?256;?header[1]?=?WIDTH_RES?/?256;?header[2]?=?HEIGHT_RES?%?256;
header[3]?=?HEIGHT_RES?/?256;?header[4]?=?bits;?header[5]?=?0;
pFile?=?fopen(“picture.tga“?“wb“);//以寫的方式打開文件
fwrite(tgaHeader?sizeof(tgaHeader)?1?pFile);//寫入文件頭
fwrite(header?sizeof(header)?1?pFile);//寫入信息
fwrite(PB?WIDTH_RES*HEIGHT_RES*colorMode?1?pFile);//寫入圖像數據
fclose(pFile);
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-08-10?13:36??tga\
?????目錄???????????0??2018-08-10?13:36??tga\tga\
?????文件?????????876??2018-08-10?12:31??tga\tga.sln
?????文件????????9728??2018-08-10?12:31??tga\tga.suo
?????文件???????18944??2018-08-10?13:36??tga\tga.v12.suo
?????文件??????921618??2018-08-10?13:34??tga\tga\picture.tga
?????文件????????3216??2018-08-10?12:31??tga\tga\tga.vcxproj
?????文件?????????941??2018-08-10?12:31??tga\tga\tga.vcxproj.filters
?????文件?????????143??2018-08-10?12:31??tga\tga\tga.vcxproj.user
?????文件????????1616??2018-08-10?13:34??tga\tga\源.cpp
- 上一篇:C++前中后綴表達式轉表達式二叉樹
- 下一篇:100套題庫全國計算機二級c語言
評論
共有 條評論