C#實現(xiàn)文字視頻生成器的示例代碼_第1頁
C#實現(xiàn)文字視頻生成器的示例代碼_第2頁
C#實現(xiàn)文字視頻生成器的示例代碼_第3頁
C#實現(xiàn)文字視頻生成器的示例代碼_第4頁
全文預覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

第C#實現(xiàn)文字視頻生成器的示例代碼目錄前言實現(xiàn)功能開發(fā)環(huán)境實現(xiàn)代碼實現(xiàn)效果

前言

簡單的描述下寫這個軟件的背景吧。之前短視頻平臺很火的時候,相信很多人都想進去分一杯羹,俺當然也不能免俗,但是人丑家窮又沒才藝,咋辦呢?看到別人有只發(fā)文字啥的一些視頻加點背景音樂也能看,想著,WoCao?,這我也行啊,ICanIUp。但是讓我天天去找素材剪輯視頻啥的,那肯定干不來,畢竟程序員是需要加班的,所以,這個粗糙的程序就誕生了,當然我也沒怎么用,發(fā)了兩篇覺得不好玩。就沒再玩了。

后來通過種種途徑吧,才知道短視頻背后的產(chǎn)業(yè)相當復雜,一個視頻能不能火基本不在于視頻本身。

這個軟件主要是基于錄屏功能來實現(xiàn)的,不過是一鍵式的罷了,當然實現(xiàn)錄屏我們用了第三方的插件:AForge。項目需要的DLL如下圖:

實現(xiàn)功能

利用錄屏功能錄制語句的生成過程,并保存成視頻格式

開發(fā)環(huán)境

開發(fā)工具:VisualStudio2013

.NETFramework版本:4.5

實現(xiàn)代碼

publicclassRecordingUtil

VideoFileWritervfWriter=newVideoFileWriter();

ScreenCaptureStreamscStream=null;

readonlyRectangleRect;

publicRecordingUtil(Rectanglerect,intinterval=40)

Rect=rect;

scStream=newScreenCaptureStream(rect,interval);

scStream.NewFrame+=(s,e1)=

vfWriter.WriteVideoFrame(e1.Frame);

publicvoidStart(stringsavePath,intRate=4000*1024)

vfWriter.Open(savePath,Rect.Width,Rect.Height,25,VideoCodec.MPEG4,4000*1024);

scStream.Start();

publicvoidStop()

if(scStream!=nullscStream.IsRunning)

scStream.Stop();

if(vfWriter.IsOpen)

vfWriter.Close();

privatevoidbtnCreate_Click(objectsender,EventArgse)

checkNull();

btnCreate.Text="正在生成";

btnCreate.Enabled=false;

SaveFileDialogsfd=newSaveFileDialog();

sfd.Filter="視頻文件|*.MP4";

if(sfd.ShowDialog()==DialogResult.OK)

Pointpoint=newPoint(this.Location.X+5,this.Location.Y+25);

Sizesize=newSize(splitContainer1.Panel1.Width%2==1splitContainer1.Panel1.Width-1:splitContainer1.Panel1.Width,splitContainer1.Panel1.Height%2==1splitContainer1.Panel1.Height-1:splitContainer1.Panel1.Height);

Rectanglerect=newRectangle(point,size);

RecordingUtilRecording=newRecordingUtil(rect);

Recording.Start(sfd.FileName);

createText(txtWord.Text);

Recording.Stop();

btnCreate.Text="生成";

btnCreate.Enabled=true;

privatevoidbtnPreview_Click(objectsender,EventArgse)

checkNull();

btnPreview.Text="正在預覽";

btnPreview.Enabled=false;

createText(txtWord.Text);

btnPreview.Text="預覽";

btnPreview.Enabled=true;

privatevoidcheckNull()

if(string.IsNullOrWhiteSpace(txtWord.Text))

toolTip1.Hide(txtWord);

toolTip1.Show("不可為空!",txtWord,5,-60,2000);

return;

privatevoidcreateText(stringtext)

Graphicsg=splitContainer1.Panel1.CreateGraphics();

g.Clear(splitContainer1.Panel1.BackColor);

Fontfont=newFont("華文行楷",25);

//BrushwhiteBrush=newSolidBrush(Color.FromArgb(0,192,0));

BrushwhiteBrush=newSolidBrush(Color.Black);

intx=0,y=0;

string[]arr=txtWord.Text.Split('\n');

for(inti=0;iarr.Length;i++)

x=40*i+15;

for(intj=0;jarr[i].Length;j++)

y=40*j+15;

g.DrawString(arr[i][j].ToString(),font,whiteBrush,x,y);

Delay(300);

privatevoidDelay(doublemm)

DateTimenow=DateTime

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論