举报

怎么让图片适应背景

0

#include <graphics.h>
#include <string>


int idx_current_anim = 0;


const int PLAYER_ANIM_NUM = 6;


IMAGE img_player[PLAYER_ANIM_NUM];


void LoadAnimation()
{
 for (size_t i = 0; i < PLAYER_ANIM_NUM; i++)
 {
 std::wstring path = L"img/player-" + std::to_wstring(i) + L".png";
 loadimage(&img_player[i], path.c_str());
 }
}
int main()
{
 initgraph(1280, 720);


 bool running = true;


 ExMessage msg;
 IMAGE img_background;


 LoadAnimation();
 loadimage(&img_background, _T("img/background.jpg"));


 BeginBatchDraw();


 while (running)
 {
 DWORD start_time = GetTickCount();


 while (peekmessage(&msg))
 {


 }


 static int counter = 0;
 if (++counter % 5 == 0)
 idx_current_anim++;


 idx_current_anim %= PLAYER_ANIM_NUM;


 cleardevice();


 putimage(0, 0, &img_background);
 putimage(500, 200, &img_player[idx_current_anim]);


 FlushBatchDraw();


 DWORD end_time = GetTickCount();
 DWORD delta_time = end_time - start_time;
 if (delta_time < 1000 / 144)
 {
 Sleep(1000 / 144 - delta_time);
 }
 }


 EndBatchDraw();


 return 0;
}

举报
0

参考 https://docs.easyx.cn/zh-cn/loadimage

// 从图片文件获取图像(bmp/gif/jpg/png/tif/emf/wmf/ico)
void loadimage(
    IMAGE* pDstImg,            // 保存图像的 IMAGE 对象指针
    LPCTSTR pImgFile,        // 图片文件名
    int nWidth = 0,            // 图片的拉伸宽度
    int nHeight = 0,        // 图片的拉伸高度
    bool bResize = false    // 是否调整 IMAGE 的大小以适应图片
);

ava
Sentence

昨天 9:40

技术讨论社区