![]()  | 
![]()  | 
![]()  | 
![]()  | 
![]()  | 
This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs. | 
Make a given color transparent in an image, using chroma if possible
int PhMakeTransparent( PhImage_t *image,
                       PgColor_t trans_color );
ph
PhMakeTransparent() makes the given trans_color transparent in the given image. This function is similar to PhMakeTransBitmap(), but PhMakeTransparent() uses chroma when possible; chroma is accelerated by most hardware, whereas transparency bitmaps are always implemented in software.
![]()  | 
If the image is palette-based, and the specified color appears more than once in the palette, both become transparent if chroma is used. In this case, PhMakeTransparent() calls PhMakeTransBitmap() to create a transparency mask. | 
The trans_color argument is the RGB color in the image's palette to be made transparent. You can pass an index into the palette as trans_color by ORing it with Pg_INDEX_COLOR. For example:
if ( PhMakeTransparent( my_image,
                        n | Pg_INDEX_COLOR ) == 0 )
{
    ...
}
To draw the image, use PgDrawPhImage() or PgDrawPhImagemx().
/*
 * This is code for a PhAB application that demonstrates
 * how to make an image transparent.  It also shows how
 * to take that image, put it into a label widget, and
 * draw it on a PtRaw's canvas.
 */
/* Standard headers */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
/* Toolkit headers */
#include <Ph.h>
#include <Pt.h>
#include <Ap.h>
/* Local headers */
#include "abimport.h"
#include "proto.h"
ApDBase_t   *database;
PhImage_t   trans_image;
/*
 * Setup function for the base window
 */
int
base_window_setup( PtWidget_t *link_instance,
                   ApInfo_t *apinfo,
                   PtCallbackInfo_t *cbinfo )
{
    PhImage_t   *imgptr;
    /* Get the original image from an image-type
       label widget that we've put in a PhAB picture
       module - don't close the database since we'll
       still be using its image and palette data. */
    database = ApOpenDBase( ABM_our_picture_module );
    imgptr = ApGetImageRes( database, "image_label" );
    /* Copy it so that we don't change the original
       PhImage_t; we'll still be using the same image
       and palette data though. */
    memcpy( &trans_image, imgptr, sizeof(PhImage_t) );
    /* Make all the white pixels transparent. */
    PhMakeTransparent( &trans_image, Pg_WHITE );
    /* Put the transparent image into another
       image-type label. */
    PtSetResource( ABW_destination_label,
       Pt_ARG_LABEL_IMAGE, &trans_image, 0 );
    /* eliminate 'unreferenced' warnings */
    link_instance = link_instance, apinfo = apinfo;
    cbinfo = cbinfo;
    return( Pt_CONTINUE );
}
/*
 * Draw function (Pt_ARG_RAW_DRAW_F) for a PtRaw widget
 */
void
raw_draw_f( PtWidget_t *widget, PhTile_t *damage )
{
    PhPoint_t   pos = {0, 0};
    PhRect_t    rect;
    damage = damage;
    PtSuperClassDraw( PtBasic, widget, damage );
    /* Find our canvas. */
    PtCalcCanvas( widget, &rect );
    /* Set translation so that drawing is relative to
       the PtRaw widget, not its parent. */
    PgSetTranslation( &rect.ul, Pg_RELATIVE );
    /* Clip to our basic canvas (it's only polite). */
    PtClipAdd( widget, &rect );
    /* Do our drawing. */
    PgDrawPhImagemx( &pos, &trans_image, 0 );
    /* Remove our translation and clipping by
       subtracting what we added above. */
    rect.ul.x *= -1;
    rect.ul.y *= -1;
    PgSetTranslation( &rect.ul, Pg_RELATIVE );
    PtClipRemove();
}
Photon
| Safety: | |
|---|---|
| Interrupt handler | No | 
| Signal handler | No | 
| Thread | No | 
PgColor_t, PgDrawPhImage*(), PgDrawPhImageRect*(), PgDrawRepPhImage*(), PhCreateImage(), PhImage_t, PhMakeTransBitmap()
"Images" in the Raw Drawing and Animation chapter of the Photon Programmer's Guide
![]()  | 
![]()  | 
![]()  | 
![]()  |