定义Image类对象时构造函数好像不能为空,例如Image fullmap(L"bj.bmp");创建图片对象时要选择图片,更别说Image map[3];这样创建数组=.=
这个函数之前用GDI写的,用的是位图数组HBITMAP map[3];,改用GDI+就不知道怎么写了=.=求教.
void GDIplus::map45scene(HWND hWnd) // 45度斜角地图
{
Graphics graphics(hWnd);
const int rows = 8,cols = 8;
int mapIndex[rows*cols] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 2, 1, 2, 0, 0, 0,
0, 0, 1, 1, 1, 0, 0, 0,
0, 0, 2, 1, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};
Image map[3]; //出错error C2248: “Gdiplus::Image::Image”: 无法访问 protected 成员(在“Gdiplus::Image”类中声明)
WCHAR filename[20];
int rowNum, colNum;
int i, x, y;
int xstart,ystart;
xstart = 32 * (rows-1); // 起始贴图坐标
ystart = 0;
Image fullmap(L"bj.bmp");
for(i=0;i<3;i++) // 加载各图块位图
{
swprintf(filename,L"map%02d.png",i);
map.FromFile(filename);
}
graphics.DrawImage(&fullmap, 0, 0);
for(i=0;i<rows*cols;i++) // 按mapindex进行地图拼接
{
rowNum = i / cols; // 行(y)编号
colNum = i % cols; // 列(x)编号
x = xstart + colNum * 32 + rowNum * (-32); // 贴图x坐标
y = ystart + rowNum * 16 + colNum * 16; // 贴图y坐标
graphics.DrawImage(&map[mapIndex],x,y);
}
} |