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:
- 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:
void CAviFromImgDlg::OnFileOpenimage()
{
CString strFilter; CSimpleArray<guid> aguidFileTypes;
HRESULT hResult;
CImage img; hResult = img.GetImporterFilterString(strFilter, aguidFileTypes, _T("All Images"));
if (FAILED(hResult)) { CString fmt;
fmt.Format(_T("Error %d\n%s"), hResult, _com_error(hResult).ErrorMessage());
MessageBox(fmt, _T("Error:"), MB_OK | MB_ICONERROR);
return;
}
CFileDialog dlg(TRUE, _T("*"), _T("*.*"), OFN_FILEMUSTEXIST| OFN_ALLOWMULTISELECT, strFilter);
dlg.m_ofn.nFilterIndex = 0; CString fileName; wchar_t* p = fileName.GetBuffer(FILE_LIST_BUFFER_SIZE); dlg.m_ofn.lpstrFile = p; dlg.m_ofn.nMaxFile = FILE_LIST_BUFFER_SIZE;
if (dlg.DoModal() != IDOK) return;
fileName.ReleaseBuffer();
wchar_t* pBufEnd = p + FILE_LIST_BUFFER_SIZE - 2; wchar_t* start = p; while ((p < pBufEnd) && (*p)) p++;
if (p > start)
{
m_imgDir = start; p++;
int fileCount = 1; while ((p < pBufEnd) && (*p)) {
start = p; while ((p < pBufEnd) && (*p))
p++;
if (p > start)
{
m_imgList.AddString(start); m_imgArray.Add(m_imgDir + _T("\\") + CString(start));
}
p++; fileCount++; }
if (fileCount == 1) {
m_imgList.AddString(dlg.GetFileName());
m_imgArray.Add(dlg.GetPathName());
}
}
m_btnOk.EnableWindow(m_imgList.GetCount() > 1); } </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