Returns the internal true-color representation of an image.
NOTE: This function is useful to read the image pixels directly or to convert an image to another format like PNG, JPEG, or GIF using a foreign library. For more information consult the Windows API documentation.
Contents |
string wb_get_image_data (int image [, int compress4to3])
Returns a string of data containing a copy of the internal true-color representation of the given image.
<?
// This example has no main window: it is a console application
include_once("../include/winbinder.php");
include_once("../include/fi/freeimage.inc.php");
// Create a true-color bitmap and draw something on it
$bmp = wb_create_image(120, 20);
wb_draw_rect($bmp, 0, 0, 120, 20, 0xA0F0E0);
$font = wb_create_font("Arial", 8);
wb_draw_text($bmp, "This is a test image.", 0, 0, 120, 20, $font, WBC_CENTER);
// Copy the bitmap color data to a DIB and save it as a PNG file
$pixeldata = wb_get_image_data($bmp, true);
$dib = FreeImage_Allocate(120, 20, 24);
wb_poke(FreeImage_GetBits($dib), $pixeldata);
FreeImage_Save(FIF_PNG, $dib, "test.png");
// Cleanup
wb_destroy_image($bmp);
FreeImage_Unload($dib);
?>