Environment: WinCE 3.0 \ Pocket PC 2002 : MVCE 3.0 PPC 2002 SDK: MCF
Display images using imgdecmp.dll and modifed VOImage wrapper class.
( I took the liberty of making CVOImage::g_iScale public -> I should
keep this private and create set\get (limited time).)
This shows how to use Pocket PCs IMGDECMP.dll image processor through the free CVOImage class libraries. Using embeded Visual C++ and the Pocket PC 2002 SDK (MFC) I have created a simple image viewer which loads graphics files from disk. Tested on iPaq 3850.
The program looks for files in \My Documents\album\ and adds them to a combobox. The image is displayed when clicked ( or scrolled to ) in the combo box. You should create a folder named ‘album’ under ‘My Documents’ and put any images you would like to view in there.
See http://www.microsoft.com/mobile/developer/technicalarticles/graphics.asp to display images loaded as resources.
Using IMGDECMP.dll
Microsoft uses the IMGDECMP DLL in Microsoft Internet Explorer for the Pocket PC to display JPEG, GIF, BMP, PNG, and other standard graphics file formats. There are several reasons for using the IMGDECMP DLL to decode the graphics in your own applications:
- By using a common component such as the IMGDECMP DLL, you reduce the memory footprint of your application.
- You will not be shipping the decoding code with your product, so you can avoid licensing patented code, such as the GIF format, which is owned by CompuServe and normally requires a licensing royalty.
- Performance is very good.
- The code has been tested thoroughly and is very stable.
- You can code directly to the IMGDECMP DLL if you wish. Conduits Technologies has an excellent Web site dedicated to this.
BOOL CImageDlg::OnInitDialog()
{
CDialog::OnInitDialog();// Set the icon for this dialog. The framework does
// this automatically when the application’s main
// window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small iconCenterWindow(GetDesktopWindow()); // center to the
// hpc screenCVOImage image;
RECT pic_rect;
m_picture_window.GetWindowRect(&pic_rect);_WIN32_FIND_DATAW *FindFileDataStruct =
new _WIN32_FIND_DATAW;HDC picDC = ::GetDC(m_picture_window.m_hWnd );
//
// find all the files in ‘\My Documents\album\’ and
// put them in the list
//HANDLE search_handle =
::FindFirstFile((LPCTSTR)_T(“\\My Documents\\album\\*.*”),
FindFileDataStruct);
if( search_handle == INVALID_HANDLE_VALUE )
{
m_combo1.AddString( (LPCTSTR) _T(“No Files Found”));
}else{
m_combo1.AddString((LPCTSTR) FindFileDataStruct->cFileName);
}while(::FindNextFile(search_handle, FindFileDataStruct) != 0 )
{
m_combo1.AddString((LPCTSTR) FindFileDataStruct->cFileName);
}//
// Show first in list
//m_combo1.SetCurSel(0);
//
// close the search handle and clean up
//::FindClose ( search_handle);
delete FindFileDataStruct;//
// Set the slider range
//m_scale.SetRange(1,10);
m_scale.SetPos(10);return TRUE; // return TRUE unless you set the
// focus to a control
}void CImageDlg::OnSelchangeCombo1()
{CVOImage image;
RECT pic_rect;
m_picture_window.GetWindowRect(&pic_rect);
HDC picDC = ::GetDC(m_picture_window.m_hWnd );//
// Show the selected picture
//CString path = _T(“\\My Documents\\album\\”);
CString image_name = “”;
m_combo1.GetLBText( m_combo1.GetCurSel(), image_name);CString path_fname = path + image_name;
//
// Load the image
//image.Load (picDC ,path_fname );
if( this->m_stretch_image.GetCheck() == BST_CHECKED)
{
//
// If you want to maintain the aspect ratio then
// modify this!
//image.Draw (picDC,
10,
10,
pic_rect.bottom – pic_rect.top,
pic_rect.right – pic_rect.left – 10);}else{
image.Draw (picDC ,10,10 );
}//
// Release the DC;
//::ReleaseDC( m_picture_window.m_hWnd, picDC);
}
void CImageDlg::OnCheckStretch()
{
CVOImage image;
RECT pic_rect;
m_picture_window.GetWindowRect(&pic_rect);
HDC picDC = ::GetDC(m_picture_window.m_hWnd );//
// Show the selected picture
//CString path = _T(“\\My Documents\\album\\”);
CString image_name = “”;
m_combo1.GetLBText( m_combo1.GetCurSel(), image_name);CString path_fname = path + image_name;
// m_picture_window.SetWindowText(image_name);
image.Load (picDC ,path_fname );
if( this->m_stretch_image.GetCheck() == BST_CHECKED)
{
image.Draw (picDC,
10,
10,
pic_rect.bottom – pic_rect.top,
pic_rect.right – pic_rect.left – 10 );
}else{
image.Draw (picDC ,10,10 );
}//
// Releae the DC;
//::ReleaseDC( m_picture_window.m_hWnd, picDC);
}void CImageDlg::OnHScroll(UINT nSBCode,
UINT nPos,
CScrollBar* pScrollBar)
{//
// Set the scale and re display the picture.
//if( pScrollBar->m_hWnd == this->m_scale.m_hWnd) // Ensure the
// correct scroll bar
{int curpos = this->m_scale.GetPos();
int cur_scale = (int) curpos * 10;//
// Made CVOImage::g_iScale public -> I should keep private
// and create set\get (limited time).
// Set the scale onCVOImage::g_iScale = cur_scale;
char s_scale[16];sprintf(s_scale, “%d”, cur_scale);
m_edit_scale.SetWindowText((CString)s_scale);CVOImage image;
RECT pic_rect;//
// The display window RECT
//m_picture_window.GetWindowRect(&pic_rect);
//
// The HDC of the display window
//HDC picDC = ::GetDC(m_picture_window.m_hWnd );
//
// Show the selected picture
//CString path = _T(“\\My Documents\\album\\”);
CString image_name = “”;
m_combo1.GetLBText( m_combo1.GetCurSel(), image_name);CString path_fname = path + image_name;
image.Load (picDC ,path_fname );
if( this->m_stretch_image.GetCheck() == BST_CHECKED)
{
image.Draw (picDC,
10,
10,
pic_rect.bottom – pic_rect.top,
pic_rect.right – pic_rect.left – 10);
}else{
image.Draw (picDC ,10,10 );
}//
// Releae the DC;
//::ReleaseDC( m_picture_window.m_hWnd, picDC);
}CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}