1

I'm trying to build a C#.NET application from the source code of a solution provided here.

I've already added a reference to AForge.Video.FFMPEG.dll, but I am still getting the following error:

Error 2 The type or namespace name 'ImageEntitiesContainer' could not be found (are you missing a using directive or an assembly reference?) C:\WorkSpace\Visual Studio 2013\Projects\CSharp\ImagesToVideo\Program.cs 56 40 ImagesToVideo

I searched for this error and found a few posts, but nothing that helps. I tried changing the target framework from my default ".NET Framework 4.5" to some other frameworks: ".NET Framework 2.0", ".NET Framework 3.0", ".NET Framework 4.0", but without any success. Does anyone have any idea why I am still getting this error?

Here is my full source code:

using AForge.Video.FFMPEG;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AForge.Video.FFMPEG
{
public class MovieMaker
{

    public void Start()
    {
        var startDate = DateTime.Parse("12 Mar 2012");
        var endDate = DateTime.Parse("13 Aug 2012");

        CreateMovie(startDate, endDate);
    }


    /*THIS CODE BLOCK IS COPIED*/

    public Bitmap ToBitmap(byte[] byteArrayIn)
    {
        var ms = new System.IO.MemoryStream(byteArrayIn);
        var returnImage = System.Drawing.Image.FromStream(ms);
        var bitmap = new System.Drawing.Bitmap(returnImage);

        return bitmap;
    }

    public Bitmap ReduceBitmap(Bitmap original, int reducedWidth, int reducedHeight)
    {
        var reduced = new Bitmap(reducedWidth, reducedHeight);
        using (var dc = Graphics.FromImage(reduced))
        {
            // you might want to change properties like
            dc.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            dc.DrawImage(original, new Rectangle(0, 0, reducedWidth, reducedHeight), new Rectangle(0, 0, original.Width, original.Height), GraphicsUnit.Pixel);
        }

        return reduced;
    }

    /*END OF COPIED CODE BLOCK*/


    private void CreateMovie(DateTime startDate, DateTime endDate)
    {
        int width = 320;
        int height = 240;
        var framRate = 200;

        using (var container = new ImageEntitiesContainer())
        {
            //a LINQ-query for getting the desired images
            var query = from d in container.ImageSet
                        where d.Date >= startDate && d.Date <= endDate
                        select d;

            // create instance of video writer
            using (var vFWriter = new VideoFileWriter())
            {
                // create new video file
                vFWriter.Open("nameOfMyVideoFile.avi", width, height, framRate, VideoCodec.Raw);

                var imageEntities = query.ToList();

                //loop throught all images in the collection
                foreach (var imageEntity in imageEntities)
                {
                    //what's the current image data?
                    var imageByteArray = imageEntity.Data;
                    var bmp = ToBitmap(imageByteArray);
                    var bmpReduced = ReduceBitmap(bmp, width, height);

                    vFWriter.WriteVideoFrame(bmpReduced);
                }
                vFWriter.Close();
            }
        }

    }
}
}
Community
  • 1
  • 1
KeithJ
  • 151
  • 2
  • 10
  • When you right click on `ImageEntitiesContainer` do you see an option titled `Resolve`? – AlphaDelta Apr 10 '15 at 04:01
  • Unfortunately no I don't see an option to "Resolve" after right-clicking on ImageEntitiesContainer. – KeithJ Apr 10 '15 at 04:07
  • I can't seem to find `ImageEntitiesContainer` anywhere in the AForge.NET source, are you sure that class even exists? – AlphaDelta Apr 10 '15 at 04:11
  • Well no I'm not sure, however others in the [original post](http://stackoverflow.com/questions/9744026/image-sequence-to-video-stream/12376324#answer-12376324) I linked to seemed to have got it working. – KeithJ Apr 10 '15 at 04:12
  • 1
    I think the `ImageEntitiesContainer` is an undocumented class in the linked SO answer, only. It seems to hold a number of `ImageSet` objects, which are fetched from the database in the example. You should easily be able to construct your own `ImageEntitiesContainer` class, in the linked example it is only used as a data container. – Anders Gustafsson Apr 10 '15 at 05:45
  • Thanks Anders, your response helps a lot, since I am still new to C#.NET and programming in general. But this will help get me on the right track. – KeithJ Apr 10 '15 at 05:54

1 Answers1

1

The ImageEntitiesContainer is not a class but a Data Source.You can figure it out in the LINQ-query code:

using (var container = new ImageEntitiesContainer())
{
    //a LINQ-query for getting the desired images
    var query = from d in container.ImageSet
                where d.Date >= startDate && d.Date <= endDate
                select d; 

ImageEntitiesContainer is the ADO.Net Entity Data Model which you have to create it by yourself.

ImageSet is a table in ImageEntitiesContainer.

The picture was captured from the link you provided:

enter image description here

Angus Chung
  • 1,421
  • 1
  • 9
  • 12
  • Thanks Angus, I thought maybe I could still get the code to work and was expecting an error about not being able to find a database if that was the issue. I guess I'll have to setup a way to capture all JPG files in a folder and use that as my source, since I won't be using a database. – KeithJ Apr 10 '15 at 07:27
  • Yes @KeithJ,you can follow it or use your own way to get data.Good luck. – Angus Chung Apr 10 '15 at 07:32