Cisco Phone Photo Who cares that I don’t have a face? It’s still cool!

Below is the code I used to tap into the CIPIMAGE API and convert a .jpg image from our PeopleSoft database into a valid .cip image at runtime. Specifically it uses the “ImageProcessor” object to convert the image from a jpeg into XML data to be parsed by the phone.

This code will also require my Cisco Phone Object Class. The cipimage.dll is included in this post below. Be sure to register cipimage.dll on your web server!

 

 

Here’s the code:

Imports CiscoIPPhoneServices

Imports System.Data

Imports System.Data.SqlClient

Imports CIPIMAGE

Partial Class physdir_show_details

Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Response.ContentType = “text/xml”

Dim ImgProc As New ImageProcessor

‘Establish connection with database

Dim SQLConnect As New SqlConnection(ConfigurationManager.AppSettings(“ConnectionStringName”))

Dim SQLCommand_Info As New SqlCommand(“stored_procedure_to_receive_info_from_db”, SQLConnect)

SQLCommand_Info.CommandType = CommandType.StoredProcedure

SQLCommand_Info.Parameters.AddWithValue(“@empid”, Request.QueryString(“empid”).ToString)

‘Prepare the table

Dim Adapter As New SqlDataAdapter(SQLCommand_Info)

Dim DT As New DataTable

Adapter.Fill(DT)

Dim EmpPhoto As String = “”

Dim EmpName As String = DT.Rows(0).Item(“EmployeeName”)

Dim pWidth As Integer = 52

If DT.Rows(0).IsNull(“EmpPhoto”) = False Then

Dim bEmpPhoto As Byte() = DT.Rows(0).Item(“EmpPhoto”)

ImgProc.LoadJPGFromBuffer(bEmpPhoto)

ImgProc.SetLocation(-1, -1)

ImgProc.Resize(52, 65)

ImgProc.ColorToGray()

ImgProc.ReducePaletteColors(4)

EmpPhoto = ImgProc.SaveCIPDataToBuffer()

EmpPhoto = Left(EmpPhoto, EmpPhoto.Length – 6)

Else

‘No photo Hex ASCII string

EmpPhoto = “<Insert a valid ASCII string for a picture that will display when the employee does not have a photo>”

EmpName = “No Photo Available”

pWidth = 87

End If

Dim CIPPD As New CiscoIPPhoneImage(“”, EmpName, -1, -1, pWidth, 65, 2, EmpPhoto, “Back”, “SoftKey:Back”, 1)

Response.Write(CIPPD)

End Sub

End Class

Download – CipImage.dll