Navigation: Ultimate Suite for PowerBuilder Help > Datawindow Controls >

Profile Picture from Blob

Send comments on this topic.

 

Profile Picture - From Blob

Display an image in a variety of frames.

Function Parameters

f_pbus_profilepicture_fromblob (unsignedlong ahdc, long ax, long ay, long awidth, long aheight, string aidentifier, string aprimarykey, integer aframethickness, string aframetype, string atheme)

Argument

 Description

 ahdc

 Always pass GetPaintDC() in the DW Expression

 ax

 Always pass GetPaintRectX() in the DW Expression

 ay

 Always pass GetPaintRectY() in the DW Expression

 awidth

 Always pass GetPaintRectWidh() in the DW Expression

 aheight

 Always pass GetPaintRectHeight() in the DW Expression

 aidentifier

 Any value you like. This value is passed as an identifier to the f_pbus_getbinarydata described later.

 aprimarykey

 This is the primary key to a table that will be queried for blob/binary data.

 aframethickness

 The pixel width of the picture frame.

 aframetype

 The shape of the picture frame. Valid values are "CIRCLE", "SQUARE", "ROUNDEDSQUARE"

 atheme

 Pass, as a string, the color of the circle. Valid values are "BLUE", "OLIVE", "SILVER", "BLACK", "CLASSIC", "PINK", "DEEPBLUE", "PURPLE", "GREEN", "ORANGE", "RED"

Implementation

This control is rendered in a computed field on your dataobject. Start by adding a computed field to your datawindow and give it the width and height that you want. You can display an image from an image file or from a blob retrieved from the database. Add an expression to the computed field that will look like this:

//Example 2 - Display image from a blob

Paint
(
    if (f_pbus_profilepicture_fromblob(GetPaintDC(),
                                       GetPaintRectX(),
                                       GetPaintRectY(),
                                       GetPaintRectWidth(),
                                       GetPaintRectHeight(),
                                       "profile picture",
                                       string( employee_emp_id ),
                                       2,
                                       "CIRCLE",
                                       cmp_theme),

          "", "Error")
)

Displaying an image from a blob retrieved from the database requires a few extra steps. The f_pbus_profilepicture_fromblob global function needs to call out to another function to retrieve a blob from the database. In advguibase.pbl, you'll see a global function called f_pbus_getbinarydata; This function is called to return binary data. You'll have to do the following steps:

1.Copy the f_pbus_getbinarydata function to one of you're own PBL's (higher in the libary list).

2.Add code to this function to interpret the Identifier and Primary Key specified in the computed expression above.

//Do a choose case on the identifier passed in. This allows us to use
//this function for other image types
 CHOOSE CASE Lower(a_identifier)
    CASE "profile picture" //This is the identifier we specified in our computed expression
         Blob Emp_id_pic
        Long ll_id
        ll_id  = Long(a_primarykey) //The primary key specified in the computed expression needs to be cast to an long

        //Use SELECTBLOB to retrieve the blob data from the database
         SELECTBLOB ProfilePicture
              INTO :Emp_id_pic
              FROM Employee
             WHERE Employee.emp_id = :ll_id
             USING SQLCA ;
  
        RETURN Emp_id_pic
END CHOOSE

//We shouldn't reach this point but
//if this function is called with an invalid identifier, return an empty blob
Blob lb
RETURN lb

Previewing Your Profile Picture

The profile picture control will not render in the painter portion of the datawindow painter. It will display in the preview section of the datawindow painter. To see the control in design time, open the preview panel in the datawindow painter and retrieve a row.

 


Copyright © 2021 Werysoft Inc.