举报

透明插入旋转图片(无背景),无法显示出来

0

这里思路是先用loadimage和rotateimage试图将图片旋转,然后在用putimage将图片插入,但是没有结果。(函数里的角度都是测量好的硬编码值),就是draw arrow函数有问题

#include <graphics.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <windows.h>
IMAGE img_arrow_origin;
typedef struct {
    POINT mouthPosition;
    POINT startPosition;
    POINT headPosition;
    POINT position;
    float velocity;
    float angle;
    BOOL is_flying;
    float time;       //记录飞行时间
    Trajectory* trail;
} Arrow;
void DrawArrow(Arrow* arrow) {
    // 参数校验
    if (!arrow || !arrow->is_flying) return;
    // 临时图像对象
    static IMAGE scaled_arrow, rotated_arrow;
    // 计算缩放比例(假设原始长度200像素)
    const float scale = 120.0f / 1724.2f;
    // 缩放操作
    Resize(&img_arrow_origin, (int)(img_arrow_origin.getwidth() * scale), (int)(img_arrow_origin.getheight() * scale));
    // 计算旋转中心
    POINT center = { scaled_arrow.getwidth() / 2,scaled_arrow.getheight() / 2 };
    // 执行旋转(角度转换为度数,调整方向)
    float draw_angle = arrow->angle * 180 / PI + 48.97; // 转换为EasyX的旋转坐标系
    rotateimage(&rotated_arrow, &scaled_arrow, draw_angle, true, 0x00000000, true);
    // 计算绘制位置(中心点对齐)
    int draw_x = arrow->position.x - rotated_arrow.getwidth() / 2;
    int draw_y = arrow->position.y - rotated_arrow.getheight() / 2;
    // 执行透明贴图
    putimage(draw_x, draw_y, &rotated_arrow);
}
int main(){
	Arrow arrow;
    loadimage(&img_arrow_origin, _T("C:\\Users\\Desktop\\Project10\\20250410193739.png"), 0, 0, FALSE, TRUE);//加载箭矢图片
	drawarrow(&arrow);
}
ava
芜湖

昨天 12:27

技术讨论社区