for connected embedded systems
![]() |
![]() |
![]() |
![]() |
PiConvertImage()
Convert an image from one type to another
Synopsis:
PhImage_t *PiConvertImage( PhImage_t *image,
PhRect_t const *bounds,
int type,
int flags )
Arguments:
- image
- A pointer to a PhImage_t structure that defines the image to be converted.
- bounds
- A pointer to a PhRect_t structure specifying a rectangle within image to convert, effectively cropping the image before converting. Pass as NULL to convert the whole image.
- type
- The type of image to convert to.
This must be one of the Pg_IMAGE_* types defined for PhImage_t. See Image types for a list of defined types.
You can pass 0 for no type conversion.
- flags
- Flags that dictate special behavior of the conversion process and can take on the following values:
- Pi_FREE
- Free the original image if the conversion succeeds. The function frees the old image by setting all its release flags and calling PhReleaseImage() on it.
- Pi_DITHER
- Not currently supported.
- Pi_CALC_PALETTE
- calculate an optimum palette during quantization. If this flag bit isn't set, the function uses the current Photon palette.
Library:
ph
Description:
This function converts a Photon image from one type to another. It allocates space for the resulting image, leaving the original image untouched. If you set the Pi_FREE flag bit, the function frees the old image by setting all its release flags and calling PhReleaseImage() on it.
Returns:
A pointer to the new, converted image on success, or NULL if an error occurred.
Examples:
This example loads a file, resizes it to 200 x 200 thumbnail, and then converts it to a palette-based image before displaying it in a PtLabel:
#include <stdlib.h>
#include <stdio.h>
/* Toolkit headers */
#include <Pt.h>
#include <photon/PxImage.h>
int main(int argc, char *argv[]) {
PtWidget_t *window;
PtArg_t args[2];
PhImage_t *img, *resized_img, *new_img;
short width = 200;
short height = 200;
if (PtInit(NULL) == -1)
PtExit(EXIT_FAILURE);
printf("Loading file: %s\n", argv[1]);
// load the image
if ( NULL== (img = PxLoadImage(argv[1], NULL ))){
printf("PxLoadImage() error.\n");
}
// resize the image
if ( NULL== (resized_img = PiResizeImage( img, NULL, width, height, 0 ))){
printf("PiResizeImage() error.\n");
}
// convert the image to the current Photon palette:
if (NULL == (new_img = PiConvertImage( resized_img, NULL, Pg_IMAGE_PALETTE_BYTE, Pi_CALC_PALETTE | Pi_DITHER ))){
printf("PiConvertImage() error.\n");
}
// setting these flags ensures the image is released
// when the widget is destroyed:
new_img->flags |= Ph_RELEASE_IMAGE|Ph_RELEASE_PALETTE|
Ph_RELEASE_TRANSPARENCY_MASK|Ph_RELEASE_GHOST_BITMAP;
window = PtCreateWidget(PtWindow, Pt_NO_PARENT, 0, NULL);
PtSetArg(&args[0], Pt_ARG_LABEL_IMAGE, new_img, 0);
PtSetArg(&args[1], Pt_ARG_LABEL_TYPE, Pt_IMAGE,0);
PtCreateWidget(PtLabel, window, 2, args);
PtRealizeWidget(window);
PtMainLoop();
return (EXIT_SUCCESS);
}
Classification:
Photon
| Safety: | |
|---|---|
| Interrupt handler | No |
| Signal handler | No |
| Thread | No |
See also:
PhCreateImage(), PhImage_t, PhRect_t, PiDuplicateImage(), PiFlipImage(), PiResizeImage()
"Images" in the Raw Drawing and Animation chapter of the Photon Programmer's Guide
![]() |
![]() |
![]() |
![]() |

![[Previous]](../prev.gif)
![[Contents]](../contents.gif)
![[Index]](../keyword_index.gif)
![[Next]](../next.gif)