c# - 如何为从资源文件夹中提取的 GIF 设置动画?
问题描述
“射手”子类
class Shooter : Box
{
public bool goleft;
public bool goright;
public Shooter(float startx, float starty)
{
pic = resizeImage (Properties.Resources.shooter, new Size(50,50)); // resize image
goleft = false;
goright = false;
x = startx;
y = starty;
}
这是它继承代码的主类。
class Box
{
public Image pic;
public float x;
public float y;
public int speed;
public Box()
{
x = 0;
y = 0;
speed = 0;
}
// Image Resizing Code
public static Image resizeImage(Image imgToResize, Size size)
{
return (Image)(new Bitmap(imgToResize, size));
}
// image resizing code
public void Draw(Graphics g)
{
g.DrawImage(pic, x, y);
}
// some code bellow that basically states the borders and hit boxes.
}
所以,是的,我只是想弄清楚如何为本质上由构造函数构建的 gif 设置动画……射击者出现了,我可以移动它,但问题是,它只是不旋转。希望大家能想办法。感谢:D
解决方案
您的 GIF 没有动画,因为您的Box
班级根本不支持它。
如果要对图像进行动画处理,不能以Bitmap的形式打开,需要获取图像数据并手动做动画,或者使用PictureBox来显示图像。这是如何手动执行此操作的示例。请注意,为了调整 GIF 的大小,您还需要逐帧进行。
推荐阅读
- assembly - far jmp 从 NASM/Intel 到 GAS/AT&T 的转换
- linux - 在 SysV Centos6 中使用环境变量
- python - 带有itertools的格雷码顺序的笛卡尔积?
- ios - 在 ARKit 应用中显示 SwiftUI 视图
- node.js - 导入数据库架构时 Express.js 类型错误
- azure - 无法在 Azure 数据工厂中获取对 cosmos db 的查询的标量值
- angular - Why we use @Injectable({ providedIn: 'root' }) to reach class?
- reactjs - material-ui 小吃吧改变颜色而不为每种颜色制作新的?
- pytorch - PyTorch 的输入类型(torch.FloatTensor)和权重类型(torch.cuda.FloatTensor)应该是一样的但是我的数据已经推送到GPU
- python - 如何遍历一个元素并使用 .split() 元素从显示的列表中删除冒号?