![]() |
![]() |
![]() |
![]() |
Convert an image from one type to another
PhImage_t *PiConvertImage( PhImage_t *image,
PhRect_t const *bounds,
int type,
int flags )
You can pass 0 for no type conversion.
ph
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.
A pointer to the new, converted image on success, or NULL if an error occurred.
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);
}
Photon
| Safety: | |
|---|---|
| Interrupt handler | No |
| Signal handler | No |
| Thread | No |
PhCreateImage(), PhImage_t, PhRect_t, PiDuplicateImage(), PiFlipImage(), PiResizeImage()
“Images” in the Raw Drawing and Animation chapter of the Photon Programmer's Guide
![]() |
![]() |
![]() |
![]() |