• 大小: 9.11MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-05
  • 语言: C/C++
  • 标签: opengl  

资源简介

利用C语言实现动画

资源截图

代码片段和文件信息

#include 
#include 
#include “CImage.h“

// 取索引图像的像素索引值。pImgSrc为图像指针,xy为像素坐标,返回像素的索引值,返回0表示出错
BYTE GetPixelIndex(const CImage* pImgSrclong xlong y)
{
if ((pImgSrc == NULL)||(pImgSrc->IsIndexed() == false)) return 0;// 图像指针为空或不是索引图像则返回0

if ((x < 0)||(y < 0)||(x >= pImgSrc->GetWidth())||(y >= pImgSrc->GetHeight())) //判断像素座标合法性
return 0;

BYTE* pDst = (BYTE*)pImgSrc->GetPixelAddress(xy);//取像素值地址
if (pImgSrc->GetBPP() == 8){ //索引值用8位表示
return *pDst;
} else {
BYTE pos;
BYTE iDst = *pDst;
if (pImgSrc->GetBPP() == 4){//索引值用4位表示
pos = (BYTE)(4 * (1 - x % 2));
iDst &= (0x0F << pos);
return (BYTE)(iDst >> pos);
} else if (pImgSrc->GetBPP() == 1){//索引值用1位表示(二值图像)
pos = (BYTE)(7 - x % 8);
iDst &= (0x01 << pos);
return (BYTE)(iDst >> pos);
}
}
return 0;
}

// 根据调色板索引值取像素值。pImgSrc为图像指针,idx为索引值,返回RGBQUAD结构的像素值
RGBQUAD GetPaletteColor(const CImage* pImgSrc BYTE idx)
{
RGBQUAD rgb = {0000};
if ((pImgSrc)&&(pImgSrc->IsIndexed())){
int ncolors = pImgSrc->GetMaxColorTableEntries();//取调色板颜色数目
RGBQUAD *prgbColors = new RGBQUAD[ncolors]; 
pImgSrc->GetColorTable(0ncolorsprgbColors);//取调色板
if (idx < ncolors)
rgb = prgbColors[idx];//得到像素值
delete [] prgbColors;
}
return rgb;
}

//取像素颜色值,对索引图像和非索引图像均适用
RGBQUAD GetPixelColor(const CImage* pImgSrclong xlong y)
{
RGBQUAD rgb={0000};
if ((!pImgSrc)||(x < 0)||(y < 0)||(x >= pImgSrc->GetWidth())||(y >= pImgSrc->GetHeight()))
return rgb;

if (pImgSrc->IsIndexed()){//索引图像
rgb = GetPaletteColor(pImgSrcGetPixelIndex(pImgSrcxy));
} else {//非索引图像
BYTE* iDst  = (BYTE*)pImgSrc->GetPixelAddress(xy);
rgb.rgbBlue = *iDst++;
rgb.rgbGreen= *iDst++;
rgb.rgbRed  = *iDst++;
if(pImgSrc->GetBPP() > 24)
rgb.rgbReserved = *iDst;
}
return rgb;
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2011-06-22 23:06  课题设计\
     文件        2030  2011-06-02 15:52  课题设计\CImage.cpp
     文件         410  2011-06-02 15:53  课题设计\CImage.h
     文件     1572918  2011-05-05 12:58  课题设计\Day.bmp
     目录           0  2011-06-25 13:29  课题设计\Debug\
     文件        5934  2011-06-21 21:05  课题设计\Debug\BuildLog.htm
     文件      106459  2011-06-17 16:08  课题设计\Debug\CImage.obj
     文件     1572918  2011-05-05 12:58  课题设计\Debug\Day.bmp
     文件       22673  2011-06-17 15:22  课题设计\Debug\haiwangxing.jpg
     文件       25787  2011-06-17 15:48  课题设计\Debug\huoxing.jpg
     文件       26213  2011-06-17 15:49  课题设计\Debug\jinxing.jpg
     文件          65  2011-06-21 21:05  课题设计\Debug\mt.dep
     文件       29555  2011-06-17 15:50  课题设计\Debug\muxing.jpg
     文件       40610  2011-06-17 15:50  课题设计\Debug\shuixing.jpg
     文件     3036054  2011-05-07 23:03  课题设计\Debug\Stars.bmp
     文件      295794  2011-05-07 10:35  课题设计\Debug\Sun.bmp
     文件       17720  2011-06-17 15:51  课题设计\Debug\tianwangxing.jpg
     文件       23965  2011-06-17 15:53  课题设计\Debug\tuxing.jpg
     文件      879616  2011-06-21 21:05  课题设计\Debug\vc90.idb
     文件      618496  2011-06-21 21:05  课题设计\Debug\vc90.pdb
     文件      118272  2011-06-21 21:05  课题设计\Debug\课题设计.exe
     文件         663  2011-06-17 16:08  课题设计\Debug\课题设计.exe.embed.manifest
     文件         728  2011-06-17 16:08  课题设计\Debug\课题设计.exe.embed.manifest.res
     文件         621  2011-06-21 21:05  课题设计\Debug\课题设计.exe.intermediate.manifest
     文件      847588  2011-06-21 21:05  课题设计\Debug\课题设计.ilk
     文件      261877  2011-06-21 21:05  课题设计\Debug\课题设计.obj
     文件     1240064  2011-06-21 21:05  课题设计\Debug\课题设计.pdb
     文件       22673  2011-06-17 15:22  课题设计\haiwangxing.jpg
     文件       25787  2011-06-17 15:48  课题设计\huoxing.jpg
     文件       26213  2011-06-17 15:49  课题设计\jinxing.jpg
     文件       29555  2011-06-17 15:50  课题设计\muxing.jpg
............此处省略13个文件信息

评论

共有 条评论