簡體   English   中英

C#保存位圖輸出

[英]C# save bitmap output

我正在創建一個使用位圖捕獲屏幕的C#程序。 而且比我想將其保存到.Avi / .mpeg文件。 但是我不知道如何將其保存到視頻中。

這是我已經擁有的代碼。

public Form1()
    {
        InitializeComponent();
    }
    static Bitmap bm;
    private void btnFolder_Click(object sender, EventArgs e)
    {
        FolderBrowserDialog folderDlg = new FolderBrowserDialog();
        folderDlg.ShowNewFolderButton = true;
        DialogResult result = folderDlg.ShowDialog();
        if (result == DialogResult.OK)
        {
            textBox1.Text = folderDlg.SelectedPath;
            Environment.SpecialFolder root = folderDlg.RootFolder;
        }
    }

    private void btnStart_Click(object sender, EventArgs e)
    {
        timer1.Start();
    }

    private void btnStop_Click(object sender, EventArgs e)
    {
        timer1.Stop();
        SaveCapture(textBox1.Text);
    }
    private void SaveCapture(string path)
    { 
        // Here should be the code to save it to mpeg/avi
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        // Take screenshot
        bm = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
        Graphics graphics = Graphics.FromImage(bm as Image);
        graphics.CopyFromScreen(0, 0, 0, 0, bm.Size);
        pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;

        // Show it in picturebox
        pictureBox1.Image = bm; 
    }

非常感謝你!

從一系列圖像創建視頻流(AVI)

我認為這可能是您最好的解決方案。 存儲所有.jpg文件,並從命令行間隔創建一個avi。 我看不到即時創建視頻如何產生“輕量級”解決方案。

您好, 點擊這里下載aviwrapper庫。 您應該編寫的代碼是這樣的:

var pngFileList = Directory.EnumerateFiles(folderImages, "*.png");
//load the first image
Bitmap bitmap = (Bitmap)Image.FromFile(pngFileList.First());
//create a new AVI file
AviManager aviManager = new AviManager(fileName, false);  // location and the name of video file

//add a new video stream and one frame to the new file
//set IsCompressed = false
VideoStream aviStream = aviManager.AddVideoStream(false, 3, bitmap);

pngFileList.Skip(1).ToList().ForEach(file =>
{
  bitmap = (Bitmap)Bitmap.FromFile(file);
  aviStream.AddFrame(bitmap);
  bitmap.Dispose();
 });

 aviManager.Close();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM