Home... About... Arrange... FAQ... Customers...

Sample 14 - Using Active Image in Microsoft Visual C++ 6.0 . 

  1. Create MFC C++ project ActiveImageCPP (Single Document , Document/View architecture) with automation support.

  2. Add the following files to the project
                     Picture.h
                     Picture.cpp
                     Memdc.h
                     ActiveImage.h
                     ActiveImage.cpp

  3. Add ActiveImage menu item to menu and create a handler for it. Add the following lines:
                     m_cPicture.ActiveImageTest(); 
                     UpdateAllViews(NULL); 

  4. Add the following code to CActiveImageCPPView::OnDraw(CDC* pDC)
                     CMemDC cDC(pDC);
                     pDoc->m_cPicture.Draw(&cDC);

  5. Add the following member to CActiveImageCPPDoc class: 
                     CPicture m_cPicture;

  6. Modify ActiveImageTest method of CPicture class. It should call Active Image component using the following code

            VARIANT w;
    
            BYTE* pBuff;
            long lBound;
            long uBound;
    
            IImages im1;
            im1.CreateDispatch("activeimage.Images");
            im1.SetImageType(1);
            im1.ReadFromFile("C:/rose.jpg");
            im1.WriteToFile("C:/test.jpg");
    
            VariantInit(&w);
            w = im1.WriteToVariableVariant();
    
            if ((w.vt & VT_ARRAY))
            {               
                    SAFEARRAY* pSA;
                    pSA= w.parray;
    
                    SafeArrayGetUBound(pSA,1,&uBound);
                    SafeArrayGetLBound(pSA,1,&lBound);
    
                    pBuff = new BYTE[uBound+1];
    
                    for(long j=lBound; j <=uBound;j++)
                    {                       
                            VARIANT v;
                            VariantInit(&v);
                            
                            SafeArrayGetElement(pSA,&j,&v);
                            
                            if (v.bVal!=NULL) 
                            {                       
                                    pBuff[j] = v.bVal;                      
                            }
                            else
                            {
                                    pBuff[j] = 0;
                            }
                    }
            
            if (m_pPicture != NULL)
                    UnLoad();       
            LoadFromBuffer(pBuff, uBound+1);
    
            delete [] pBuff;
    
            }
    
    


  7. Add include directives to ActiveImageCPPDoc.h and ActiveImageCPPView.h files
                     #include "Picture.h" 
                     #include "memdc.h" 

  8. Compile and run the project

  9. Remarks

    1. Place rose.jpg to the root directory of C:\

    2. OleLoadPicture method supports Gif, Jpeg and BMP formats only

 

 



 

rose.jpg

Picture 1. Screenshot (size - 17 Kb)



If you have any questions or bug reports, write to active.image@tonec.com for technical support.


© 2000-2001 All Rights Reserved

Tonec Inc., 16835 Algonquin Street #400, Huntington Beach, CA, 92649, fax: (509) 752-1450, e-mail: info@tonec.com