Visual Studio 状态栏中的动画图像
Animated image in Visual Studio Status bar
下面的文章解释了如何在状态栏中使用内置的 VS 动画图标。
https://msdn.microsoft.com/en-us/library/bb166795.aspx
我想知道,有没有办法在状态栏中包含自定义 gif 动画。
可以像下面这样包含位图图像。
当我根据上面的示例指向 gif 图像时,动画没有发生。请帮忙。
据我所知,没有任何方法可以直接使用gif动画图像。
正如IVsStatusbar.Animation方法提到的:
[in] If the VARIANT is a VT_I2, it refers to the SBAI_Index of
predefined animated icons. If this parameter is a VT_I4, it refers to
an HBITMAP containing the filmstrip image for animation, whose width
should be a multiple of its height.
您可以将 gif 文件转换为 BMP 图像,其宽度是其高度的倍数,方法是将 gif 图像的每一帧复制并粘贴到 BMP 文件中,然后使用第二个中提供的代码 link 你提到的。
例如,这是我创建的包含 5 个动画帧的 BMP 图像:
将此图片保存为BMP文件,使用第二个link中的代码进行调试:
private void MenuItemCallback(object sender, EventArgs e)
{
IVsStatusbar statusBar = (IVsStatusbar)ServiceProvider.GetService(typeof(SVsStatusbar));
Bitmap b = new Bitmap(@"D:\ani.bmp");
IntPtr hdc = IntPtr.Zero;
hdc = b.GetHbitmap();
object hdcObject = (object)hdc;
statusBar.Animation(1, ref hdcObject);
System.Windows.Forms.MessageBox.Show("Click OK to end status bar animation.");
statusBar.Animation(0, ref hdcObject);
DeleteObject(hdc);
}
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern bool DeleteObject(IntPtr hObject);
您将在 Visual Studio 中看到如下动画:
下面的文章解释了如何在状态栏中使用内置的 VS 动画图标。
https://msdn.microsoft.com/en-us/library/bb166795.aspx
我想知道,有没有办法在状态栏中包含自定义 gif 动画。
可以像下面这样包含位图图像。
当我根据上面的示例指向 gif 图像时,动画没有发生。请帮忙。
据我所知,没有任何方法可以直接使用gif动画图像。
正如IVsStatusbar.Animation方法提到的:
[in] If the VARIANT is a VT_I2, it refers to the SBAI_Index of predefined animated icons. If this parameter is a VT_I4, it refers to an HBITMAP containing the filmstrip image for animation, whose width should be a multiple of its height.
您可以将 gif 文件转换为 BMP 图像,其宽度是其高度的倍数,方法是将 gif 图像的每一帧复制并粘贴到 BMP 文件中,然后使用第二个中提供的代码 link 你提到的。
例如,这是我创建的包含 5 个动画帧的 BMP 图像:
将此图片保存为BMP文件,使用第二个link中的代码进行调试:
private void MenuItemCallback(object sender, EventArgs e)
{
IVsStatusbar statusBar = (IVsStatusbar)ServiceProvider.GetService(typeof(SVsStatusbar));
Bitmap b = new Bitmap(@"D:\ani.bmp");
IntPtr hdc = IntPtr.Zero;
hdc = b.GetHbitmap();
object hdcObject = (object)hdc;
statusBar.Animation(1, ref hdcObject);
System.Windows.Forms.MessageBox.Show("Click OK to end status bar animation.");
statusBar.Animation(0, ref hdcObject);
DeleteObject(hdc);
}
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern bool DeleteObject(IntPtr hObject);
您将在 Visual Studio 中看到如下动画: