环境:VS2022+EasyX
参考博客(https://blog.csdn.net/Solahalo/article/details/127598433)
写了个输出透明背景的png图的函数,请问该如何写清除图像的函数以实现画面刷新(类似XOR)
//绘制透明背景的PNG函数
inline void DrawPNG(IMAGE* dstimg, int x, int y, IMAGE* srcimg, UINT transparentcolor) {
HDC dstDC = GetImageHDC(dstimg);
HDC srcDC = GetImageHDC(srcimg);
int w = srcimg->getwidth();
int h = srcimg->getheight();
//使用Windows GDI函数实现透明位图
TransparentBlt(dstDC, x, y, w, h, srcDC, 0, 0, w, h, transparentcolor);
}
//类封装和主函数部分代码
void Player::show()
{
DrawPNG(NULL, x, y, &img_Player[direction], BLACK);
}
void Player::unshow()
{
//ErasePNG(NULL, x, y, &img_Player[direction]);
}
Player P;
P.show();
P.initStatus();
while (true) {
P.Move();
BeginBatchDraw();
P.unshow();
P.DrawStatus();
P.show();
EndBatchDraw();
Sleep(100);
}
//尝试写的清除函数,但是没效果
inline void ErasePNG(IMAGE* dstimg, int x, int y, IMAGE* srcimg) {
HDC dstDC = GetImageHDC(dstimg);
HDC srcDC = GetImageHDC(srcimg);
int w = srcimg->getwidth();
int h = srcimg->getheight();
// 使用 XOR 操作擦除图像
BitBlt(dstDC, x, y, w, h, srcDC, 0, 0, SRCINVERT);
}