用GDI画文字中双缓存使用的问题

zsrui 2016-08-31 09:06:39
我想做一个支持弹幕的视频播放器,用GDI来实时画出弹幕内容。当我尝试使用双缓存机制来解决字幕的闪烁问题时,字幕反而不显示了,请高手指点下,谢谢!

弹幕内容是"我是画出来的文字!!!"

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace dmshipin
{
public partial class Form1 : Form
{
//GDI画图的双缓存设定
private BufferedGraphics graphBuffer = null;


int danmuweizhi_x = 1500;//默认弹幕起始位置
public Form1()
{
InitializeComponent();

}

private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e)
{

axWindowsMediaPlayer1.currentPlaylist = axWindowsMediaPlayer1.newPlaylist("播放列表", "");
//遍历打开的集合
string[] bofangliebiao = new string[] { @"d:\h3.mp4", @"d:\h2.mp4", @"d:\h1.mp4" };
foreach (string fn in bofangliebiao)
{
//添加播放列表
axWindowsMediaPlayer1.currentPlaylist.appendItem(axWindowsMediaPlayer1.newMedia(fn));
}

//GDI画图的双缓存设定
graphBuffer = (new BufferedGraphicsContext()).Allocate(axWindowsMediaPlayer1.CreateGraphics(), axWindowsMediaPlayer1.DisplayRectangle);

//循环播放
axWindowsMediaPlayer1.settings.setMode("loop", true);
//播放
axWindowsMediaPlayer1.Ctlcontrols.play();



}

private void timer1_Tick(object sender, EventArgs e)
{
System.Drawing.Size size = this.Size;
System.Drawing.Point point = this.Location;

int left = this.Left;
int width = this.Width;

if (danmuweizhi_x < -400)
{
danmuweizhi_x = width - 10;
}
else {
danmuweizhi_x = danmuweizhi_x - 1;
}
label1.Location = new Point(danmuweizhi_x, 40);
label2.Location = new Point(danmuweizhi_x + 10, 80);
label3.Location = new Point(danmuweizhi_x - 5, 120);
label4.Location = new Point(danmuweizhi_x + 20, 160);

////画出的文字
//Graphics danmu = axWindowsMediaPlayer1.CreateGraphics();

//GDI画图的双缓存设定
Graphics danmu = graphBuffer.Graphics;
Font font = new Font("黑体", 24);
//Point一样,只是值是浮点类型
PointF point1 = new PointF(danmuweizhi_x + 10, 250);
SolidBrush grayBrush = new SolidBrush(Color.Gray);
danmu.DrawString("我是画出来的文字!!!", font, Brushes.White, point1);
}

}
}
...全文
237 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zsrui 2016-09-02
  • 打赏
  • 举报
回复
引用 2 楼 u012948520 的回复:
画完之后加一句this.graphBuffer.Render();


我加了这一句之后,整个视频画面都在闪烁啊, 太吓银了。截图的时候,正好是视频画面闪黑的一刻


白衣如花 2016-09-01
  • 打赏
  • 举报
回复
画完之后加一句this.graphBuffer.Render();
devmiao 2016-08-31
  • 打赏
  • 举报
回复
http://www.doc88.com/p-9019706850992.html

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧