Click here to Skip to main content
16,016,537 members
Articles / Desktop Programming / MFC

Avi from Image Files in One Click

Rate me:
Please Sign up or sign in to vote.
4.64/5 (11 votes)
27 Dec 2017CPOL7 min read 15.7K   1.2K   11   3
Simple solution for small avi demo performance from Image files of any kind

Sample Image - maximum width is 600 pixels

Introduction

When I prepared my PowerPoint presentation, I discovered that it may be well to insert some avi performance demo. The only problem occurred that I have no instrument for conversion of the screen images to avi at the moment. And as usual, I set off in quest of happiness into CodeProject. And as usual, I was lucky to find the fine article "Easy AVI" by Andy Bantly. And once again, the code was fine and the idea was fine, but a little bit poor demo presentation provided. Therefore, I dared to improve the performance for more simple use with a few clicks using standard MFC procedures.

Background

I borrowed the EasyAvi.cpp codes from the article "Easy AVI" by Andy Bantly. In the code above, I just put in comments for some parts not fit for new MFC project. All other performance has been arranged with the standard MFC Application Wizard using class CImage for all kinds of images handling.

Before you start building the project provided, it is highly recommended to have a look to the demo presentation enclosed in order to get an idea of the output expected.

Demo Explanations

The executable AviFromImg.exe in the AviFromImgDemo directory has been built with MSVS-2015 pro using the instruments of MSVS-2010. Therefore, the AviFromImg.exe is valid even for Windows-XP. Just if you want to start in Windows-XP, please do not forget to insert mfc100.dll, mfc100u.dll, msvcp100.dll, msvcr100.dll files into the AviFromImgDemo directory (or into the ..windows\system32 directory).

Some menu and some special Accelerator keys arranged in order to demonstrate the AviFromImg project implementation:

Image 2

  • Menu File->Append Image(s) - selecting the file(s) with the image to append to the list in the ListBox Control
  • Menu File->Insert Image(s) - selecting the file(s) with the image to insert into to the list in the ListBox Control before the item selected
  • Menu File->Delete Image(s) - deleting the file(s) selected from the list in the ListBox Control
  • Menu File->Clear All - deleting all the files from the list in the ListBox Control
  • Menu File->Create Avi - creating the avi file from all the files from the list in the ListBox Control (also Ok Button)
  • Menu File->Play - play last avi file created
  • ListBox Control - list of the names of the files containing images to create avi
  • OK button - creating the avi file from all the files from the list in the ListBox Control (also Menu File->Create Avi)
  • Cancel button - just close the dialog
  • Append Reverse CheckBox - if selected appending the files from the list in the ListBox Control to avi in reverse order
  • Slides per Sec EditBox - specifying number of images change per one second in avi
  • Progress Control - specifying number of images accepted in avi at the moment while creating

The order of working is as follows:

  • Once started, the list of files' names from default AviImages path from the root directory appeared. You may edit this list if required with Menu commands Append Image(s), Insert Image(s), Delete Image(s) and Clear All.
  • With the Append Image(s) and Insert Image(s) commands, the standard FileDialog Box appeared. This FileDialog Box has the multiselection property, therefore you may append and insert in the list the image files of any kind from anywhere (just keep in mind that the sizes of images must be more or less equal, better exactly equal).
  • With the Create Avi command (or OK Button pressed), the standard FileDialog Box for saving appeared. The default AviFiles path from the root directory suggested for saving. It is not compulsory, you may save the avi file with any name in any place where you like. After creating completion, the MessageBox with the pathname created appeared. Please note the image size for avi borrowed from the first image in list. All other images in avi to be obtained as a copy of a rectangle corresponding from the top left corner.
  • The last avi created may be started with Menu->Play command.

Thus, if you've originally prepared all image files required for your avi in the default AviImages folder once started, just press Ok Button and you'll receive the avi file in the default AviFiles path in the root directory in one click.

Building Notes

Solution configuration must be installed as Release and the platform to be x86.

The project provided has been developed with MSVS-2015 pro using the instruments of MSVS-2010. Therefore, the exe files are valid even for Windows-XP. If you do not need to run the application in Windows-XP, just change the instruments to MSVS-2015 .

The default coding property is UNICODE; nevertheless MBCS coding is also available, just change the property.

Even if you are first time working with MSVS, just select menu Debug->Start without debugging and the program AviFromImg.exe should start building and working.

Project Source and Data Storage

Standard source codes in AviFromImgproj path have been created with the standard MFC Application Wizard:

  • AviFromImg.cpp - defines the standard class behaviors for the application
  • AviFromImgDlg.cpp - implementation of the standard CDialogEx class; messages handling procedures created by the author using standard MFC Application Wizard procedures
  • EasyAvy.cpp - borrowed from the article "Easy AVI" by Andy Bantly; I've just put in comments for some parts not fit for new MFC project
  • AviFromImg.rc and resource.h - menu, dialog, accelerator resources created by the author using the standard Resource Wizard procedures

The default AviImages path in the root directory containing the sample images for the first program test which are the screens from my lesson "X4.UFO game" from my former article "50 OpenGL MFC Projects in One". It is not compulsory and you may change the contents of this path as you like or prepare some other directory for images storage.

The result avi created suggested for saving in the default AviFiles path from the root directory. It is not compulsory, you may save the avi file with any name in any place where you like.

Code Explanation

All the Menu and Accelerator Commands have been done with standard MFC AppWizard technologies. Therefore, I feel nothing to explain better than in the standard tutorials. Just mention the multiple file selection use in the standard FileDialog Box:

C++
  void CAviFromImgDlg::OnFileOpenimage()
{
  CString strFilter;                    //filter for CFileDialog box;
  CSimpleArray<guid> aguidFileTypes;
  HRESULT hResult;                      //result status of filter creation 

  CImage img;                          //Standard Cimage object
  hResult = img.GetImporterFilterString(strFilter, aguidFileTypes, _T("All Images"));
  if (FAILED(hResult)) {               //if the filter creation failed then cancel this proc 
    CString fmt;
    fmt.Format(_T("Error %d\n%s"), hResult, _com_error(hResult).ErrorMessage());
    MessageBox(fmt, _T("Error:"), MB_OK | MB_ICONERROR);
    return;
  }//if(FAILED(hResult))

  //Standard CFileDialog Box:
  CFileDialog dlg(TRUE, _T("*"), _T("*.*"), OFN_FILEMUSTEXIST| OFN_ALLOWMULTISELECT, strFilter);

  dlg.m_ofn.nFilterIndex = 0; //m_nFilterLoad;
  CString fileName;                                       //The string to contain 
                                                          //the files selected 
  wchar_t* p = fileName.GetBuffer(FILE_LIST_BUFFER_SIZE); //Reserve the space 
                                                          //for files selected
  dlg.m_ofn.lpstrFile = p;                                //Reference to the string 
                                                          //in  CFileDialog Box
  dlg.m_ofn.nMaxFile = FILE_LIST_BUFFER_SIZE;//#define FILE_LIST_BUFFER_SIZE
                                             //((MAX_CFileDialog_FILE_COUNT*(MAX_PATH+1))+ 1)

  if (dlg.DoModal() != IDOK)                 //start  CFileDialog Box
    return;

  fileName.ReleaseBuffer();                  //Clear Buffer

  wchar_t* pBufEnd = p + FILE_LIST_BUFFER_SIZE - 2; //The end of the buffer in CFileDialog Box
  wchar_t* start = p;                               //The beginning of the buffer 
                                                    //in CFileDialog Box
  while ((p < pBufEnd) && (*p))                     //find string end
    p++;
  
  if (p > start)
  {
    m_imgDir = start; //Path to folder where files were selected
    p++;

    int fileCount = 1;                             //number of files selected                
    while ((p < pBufEnd) && (*p))                  //read next string
    {
      start = p;                                   //specify the string found as start
      while ((p < pBufEnd) && (*p))
        p++;
      if (p > start)
      {
        m_imgList.AddString(start);           //append the file selected in the list box
        //append the pathname of the file selected in the list box$
        m_imgArray.Add(m_imgDir + _T("\\") + CString(start));
      }
      p++;                                    //next letter in the buffer in CFileDialog Box  
      fileCount++;                            //number of files selected increased
    }
   if (fileCount == 1)  //Single selection
      {
         m_imgList.AddString(dlg.GetFileName());
         m_imgArray.Add(dlg.GetPathName());
      }
  }
  m_btnOk.EnableWindow(m_imgList.GetCount() > 1);  //Create avi permitted if at least two files
                                                   //presented in the list box   
}  </guid>

Pls note that the pathname of the file selected appended to m_listArray at one time as the file name appended to the m_listBox. Thus, it is possible to create the avi from the images of any kind located in separate directories.

As for CAVI class in EasyAvi.cpp, I think it is better to refer to the author of the article "Easy AVI" by Andy Bantly.

Your Own Applications Development using the Project Provided

You may pick up all this project, rename it with the project of my former CodeProject article "MFC Project from Existing Code in One Click" and combine and improve the code as you like.

Or you may pick up the EasyAvi.cpp file from this project and to include it in any of your images handling project with menu Project->Existing Item.

Or you may simply use the AviFromImg.exe from the demo provided to arrange your images in avi file. The presentation with avi looks much better.

Your references to my code, if any, should be highly appreciated.

Points of Interest and Acknowledgements

Sure, you can use the technology of the images collected into avi with usual monster programs as CorelDraw or some other photo handling progs. But all these sophisticated programs do it with the closed sources. Therefore, you cannot arrange some tricks and effects as you like.

If you care that the avi created is too large in size, just use the online convertors in the Network provided a lot of. The sample Download Demo MP4 provided has been created from my lesson "X5.Box Play" from my former article "50 OpenGL MFC Projects in One".

Many thanks to Andy Bantly for his fine job. My presentation with avi occurred fine. Also, my grand daughter likes to make movies with simple technologies.

History

  • 28th December, 2017: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Russian Federation Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
SuggestionThanks!!! Pin
sobin kj20-Apr-18 22:38
sobin kj20-Apr-18 22:38 
QuestionNo source Pin
Stacy Dudovitz28-Dec-17 6:53
professionalStacy Dudovitz28-Dec-17 6:53 
AnswerRe: No source Pin
Rick York28-Dec-17 7:48
mveRick York28-Dec-17 7:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.