 |
  |
|
Sample 14 - Using
Active Image in Microsoft Visual C++ 6.0 .
-
Create MFC C++ project
ActiveImageCPP (Single Document , Document/View
architecture) with automation support.
-
Add the following files to the project
Picture.h,
Picture.cpp,
Memdc.h,
ActiveImage.h,
ActiveImage.cpp.
-
Add ActiveImage menu item to menu and create a
handler for it. Add the following lines:
m_cPicture.ActiveImageTest();
UpdateAllViews(NULL);
-
Add the following code to
CActiveImageCPPView::OnDraw(CDC* pDC)
CMemDC cDC(pDC);
pDoc->m_cPicture.Draw(&cDC);
-
Add the following member to CActiveImageCPPDoc
class:
CPicture m_cPicture;
-
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;
}
|
-
Add include directives to
ActiveImageCPPDoc.h and ActiveImageCPPView.h files
#include "Picture.h"
#include "memdc.h"
-
Compile and run the project
-
-
Place rose.jpg to the root directory of C:\
-
OleLoadPicture method supports Gif, Jpeg and BMP
formats only
|
|
Picture 1. Screenshot (size - 17 Kb)
|
|
|
If you have any questions or bug reports, write to active.image@tonec.com for
technical support.
|
|