winform using video as a window background

A recent project on Windows,Customer requirements to do the "flip" a little,so,Dynamic window background is always essential content (such as mobile phones qq login screen, right?

I thought this is a very easy to implement functionality so keen on the idea down ...... yes,In winform in,Not so easy to achieve the effect you want the。

Of course,We think that if you want to play video,Then the system comes with media player,Just add a control that can handle - the result is either a button to play video blocked,Or it is always first,The button block ......

So the,Want to achieve play video,Or to use honest pictureBox

Then this is to use so-called mciSendString Technique,For example, this:

But this can not be used,Even if the official code copied,You can not get the right result - just do not play your temper?

Eventually,I still use OpenCV To achieve this effect,of course,To use C #,We have to find the OpenCV .net package,That is EmguCV

Here I will look at the implementation process roughly record,First you go to the library to download Emgu install it,Address here:https://sourceforge.net/projects/emgucv/files/emgucv/3.2/libemgucv-windesktop-3.2.0.2682.exe/download

You should pay attention to the downloaded version,If a newer version is,Please download the new version。

principle

In fact, the principle of using emgu and play with pictureBox video above should be consistent,The video frames are acquired in time,Then show a picture Bale。Another benefit of using emgu is that it can be made so that any video,For instance, your mp4,Or streaming address。

Environment Configuration

After installing the download,The default installation location for the: C:\Emgu\emgucv-windesktop 3.2.0.2682\bin Specific version numbers may change。Now we open vs,Import emgu in it:

    1. Point to open your program project,The midpoint of the right mouse button in the "Design" mode on the left side of the "toolbox",Select "option…」;
    2. In the dialog box below the mid-point "Browse",Find the installation location of emgu,Select Emgu.CV.UI.dllZedgraph.dll Both were open;
    3. VS will automatically import controls and check these emgu,Be determined;
    4. In the "Solution Explorer" on the right side of the project,Find the "reference",In the inside right click select "Add Reference";
    5. On the left side of the pop-up dialog box select "Browse",And then manually import Emgu.CV.UI.dllZedgraph.dllEmgu.CV.UI.GL.dllEmgu.CV.World.dll These four documents。

Such,Environment has configured the。

Using controls

This time you can use the drag controls from the toolbox in the emgu,Here we use the emgu ImageBox ,After dragged named it VideoBox spare。

Here we will use the class variable,Note that the statement in the class:

When you want to play video,To do so:

There are two points to note:

  1. The first 4 Line acquired the video frame rate,Not all videos can get to the right,So if you can not get,We gave a default 24 fps,of course,You can also default 25 or 30;
  2. The first 8 Note that the line must call starts,Otherwise, the video will not play,The timer does not start automatically。

Now let us look at video Controller Realization,Here is the most important,Because the timer polls the controller at a specified time,Specific display operation is performed by the controller of this:

Note that if you want to play continuously (repeat loop),Then re-initialize a highlight in a row VideoCapture Can。

Join transparent background controls

of course,Finally, we also added controls,For example, a Button ,What you need to have a set of transparent png as a button,Then do the following configuration:

Here ll Is one of my Button ,In short,After such a configuration,The button is transparent,But you will find that although it is overlaid on top of video,But clearly transparent to the background or the window itself instead of displaying the contents of its next video。

Then we can manually adjust the button of the parent for this our VideoBox ,Such,It can display the contents of the video。

dynamic link database

At last,You also need to rely on run-time dynamic link library copied to the run directory of the program,This is divided into 32-bit and 64-bit,If you run debug,To copy files in a directory 32: C:\Emgu\emgucv-windesktop 3.2.0.2682\bin\x86

References

  1. OpenCV
  2. Emgu CV: OpenCV in .NET (C#, VB, C++ and more)
  3. How to use PictureBox to play video
  4. Studies with [] Emgu EmguCV (a) configuration and using
  5. VS2010 + C # + EmguCV read and record video
  6. [emguCV]play video—Temporary notes (unfinished)

Original article written by LogStudio:R0uter's Blog » winform using video as a window background

Reproduced Please keep the source and description link:https://www.logcg.com/archives/2893.html

About the Author

R0uter

The non-declaration,I have written articles are original,Reproduced, please indicate the link on this page and my name。

Leave a Reply

Your email address will not be published. Required fields are marked *