wb_create_image

int wb_create_image (int width, int height)

Creates a true-color image measuring width by height pixels. The resulting image must be destroyed by a call to wb_destroy_image().

Using additional DIB parameters

int wb_create_image (int width, int height [int dibbmi, int dibbits])

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.

The optional dibbmi and dibbits parameters are used together to convert an image from another format to the internal Windows bitmap representation (DIB) or to create an image from raw binary data. The dibbmi parameter must be a pointer to a BITMAPINFO structure with information about the DIB, and dibbits must be a pointer to the DIB color data of the bitmap, as used in the API function SetDIBits(). For more information consult the Windows API documentation.

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.

Example

<?

// 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();

?>

See also

wb_destroy_image
wb_get_image_data
Image functions
Low-level functions