Contents |
int wb_create_image (int width, int height)
int wb_create_image (int width, int height [int dibbmi, int dibbits])
This feature is useful to read bitmap information from image formats that cannot be read directly by the Windows API, like PNG, JPEG, and GIF.
For example, the FreeImage library is a standalone DLL that provides a comprehensive set of image functions. This library (and other DLLs as well) can be easily integrated into WinBinder using functions wb_load_library(), wb_call_function() and wb_get_function_address(). The script freeimage.inc.php already implements some useful functions and is included in the distribution.
Special warning about using the extra parameters of wb_create_image
This function provides access to the Windows API and should be used with great care. This function can easily generate a runtime exception or freeze the PHP application. Worse, if you are using Windows 98 or Me, it is not unlikely to crash the whole system when calling this function. For this reason Windows 98 or Windows Me are not recommended for developing WinBinder applications. Always be careful and double-check your source code before running it when using this function.
<?
// Use the FreeImage library to display a JPEG image
// NOTE: This kind of application does not need a window handler function
include_once("../include/winbinder.php");
include_once("../include/fi/freeimage.inc.php");
// Create main window
$mainwin = wb_create_window(NULL, PopupWindow, "DIB", WBC_CENTER, WBC_CENTER, 175, 160, 0, 0);
// Perform the conversion
$filename = "../resources/cassini.jpg";
$dib = FreeImage_Load(FIF_JPEG, $filename, 0); // Open JPEG image file
$width = FreeImage_GetWidth($dib); // Get its dimensions
$height = FreeImage_GetHeight($dib);
$bmp = wb_create_image($width, $height, // Create a WinBinder handle to it
FreeImage_GetInfoHeader($dib),
FreeImage_GetBits($dib));
FreeImage_Unload($dib); // Release FreeImage handler
// Create control with image on it
$frame = wb_create_control($mainwin, Frame, "", 20, 20, $width, $height, 101, WBC_IMAGE);
wb_set_image($frame, $bmp);
wb_destroy_image($bmp);
wb_main_loop();
?>