Tonec.com Bringing Internet Technology Innovations to Market since 1991
  News Products Outsourcing About Us Contact Us
what's new?what's new? featuresfeatures samplessamples manualmanual downloaddownload buybuy
  Tonec Homepage
ProductsActive Imagesamples

Please view complete list of samples

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

  7.         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;
    
            }

  8. Add include directives to ActiveImageCPPDoc.h and ActiveImageCPPView.h files

    #include "Picture.h" 
    #include "memdc.h"

  9. Compile and run the project
  10. Remarks
    1. Place rose.jpg to the root directory of C:\
    2. OleLoadPicture method supports Gif, Jpeg and BMP formats only

 
 Picture 1. Screenshot (size - 17 Kb)

Next sample >> 

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

  TonecPrivacy Policy
  © 1999-2005. Tonec, Inc. All rights reserved.