游戏开发论坛

 找回密码
 立即注册
搜索
查看: 3909|回复: 1

GDI+编程,如何定义Image类对象数组?

[复制链接]

1

主题

1

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2012-4-8 22:16:00 | 显示全部楼层 |阅读模式
定义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);
        }
}

0

主题

15

帖子

34

积分

注册会员

Rank: 2

积分
34
发表于 2012-5-14 20:55:00 | 显示全部楼层

Re:GDI+编程,如何定义Image类对象数组?

Image的两个构造函数

Image::Image(IStream*,BOOL) Creates an Image object based on a stream.
Image::Image(WCHAR*,BOOL) Creates an Image object based on a file.

Image::Image() 是Protected.


改成下面的试试

Image *map[3]={NULL};    // 出错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 = Image::FromFile(filename);
}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-2-28 12:52

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表