|
|
|
|
|
|
|
Introduction |
FreeImage is a useful Open Source library project for converting, reading, manipulating
graphical formats. I decided to use it in my powerbuilder application. To use it
you need FreeImage.dll. You can download it at
SourceForge |
| Using the code |
You can use the workspace example.pbw in the Debug directory. Remember you must
download FreeImage.dll an put it in the application directory. The code for the
format conversion is:
n_cpp_pbni_pbfreeimage obj
obj = Create n_cpp_pbni_pbfreeimage
obj.of_convertbmp2jpg(sle_bmp.text, sle_jpeg.text) \\for bmp to jpeg conversion
obj.of_converttiff2jpg(sle_bmp.text, sle_jpeg.text) \\for tiff to jpeg conversion
|
| Implementation |
I used PBNI AppWizard for Visual Studio .NET 2003. If you don't have it go to
codexchange site and download itOpen a new
Viaual Studio project using the wizard PBNI Extension dll
I changed only the PBclass name to PBFreeImage.
Now you need FreeImage.h and FreeImage.lib. You can
download
it at SourceForge.
The major point is ConvertBmp2Jpg function in PBFreeImage.cpp.
public class // PBFreeImage.cpp : PBNI class
#include "PBFreeImage.h"
#include "FreeImage.h"
..........
..........
..............
PBXRESULT PBFreeImage::ConvertBmp2Jpg( IPB_Session *session,PBCallInfo * ci )
{
PBXRESULT pbxr = PBX_OK;
LPSTR FileName;
LPSTR FileNameOut;
IPB_Value* FileNameArg ;
IPB_Value* FileNameArgOut ;
//Retrive file names
FileNameArg = session->AcquireValue ( ci->pArgs->GetAt(0) ) ;
pbstring pbFileName = FileNameArg->GetString() ;
FileNameArgOut = session->AcquireValue ( ci->pArgs->GetAt(1) ) ;
pbstring pbFileNameout = FileNameArgOut->GetString() ;
FileName = (LPSTR)session->GetString ( pbFileName ) ;
FileNameOut = (LPSTR)session->GetString ( pbFileNameout ) ;
//---------------------------------------------------------
//call FreeImage functions
FIBITMAP *dib =FreeImage_Load(FIF_BMP, _T(FileName) , 0);
FreeImage_Save(FIF_JPEG, dib, _T(FileNameOut), 0);
//----------------------------------------------------------
ci->returnValue->SetString( _T("Hello") );
return pbxr;
}
PBXRESULT PBFreeImage::ConvertTiff2Jpg( IPB_Session *session,PBCallInfo * ci )
............
FreeImage_Load and FreeImage_Save are implemented in FreeImage.dll.
Compile the project, ifyou have problems refer to "PowerBuilder Native Interface
Programmer's Guide and Reference"
Now you have only to build the pbd file using pbx2pbd100.exe
(or pbx2pbd90.exe).
Now you can add the pbd to an existing PowerBuilder target and
use the functions of the user object.
|
|
Download |
The entire project (PB10)
Download(.Net)
REMEMBER: you have to put FreeImage.h, FreeImage.lib in project folder and
FreeImage.dll in Debug folder. Those files are not included in the .ZIP.
You can use this link SourceForge
|
|
|
|