Using csImageFile in Visual Basic

csImageFile can be used with Visual Basic. The instructions that are included with the component are aimed at ASP developers using VBScript, so the main points of interest for VB users are explained here.

We also have an ActiveX / OCX control, csXImage, and in most cases this is more suitable for use in a visual environment.

First the csImageFile DLL must be registered on the machine that will run the application. There is a detailed description of registration here if you are not familiar with this.

Next, import the type library into Visual Basic. In the VB development environment select "Project" from the menu bar, then "References". The dialogue box will then show available type libraries. Scroll down to "csImageFile Library", check the box and click OK. This will add the "manage" class from csImageFile to the Object Browser making it available for early binding.

We have a simple example project that you can download. It draws a piece of text and a rectangle. More importantly it demonstrates how to display the image in a VB picture box and this is what takes up most of the code.

Download the example - vbimage.zip (2 KB)

Download the trial csImageFile component - csift.zip (1 MB)

The code for the example is listed below.

Private Type PicBmp
  Size As Long
  Type As Long
  hBmp As Long
  Reserved As Long
End Type

Private Type GUID
  Data1 As Long
  Data2 As Integer
  Data3 As Integer
  Data4(7) As Byte
End Type

Private Declare Function OleCreatePictureIndirect Lib _
  "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, _
  ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long

Private Sub Command1_Click()
  Dim Image As manage
  Dim Pic As PicBmp
  Dim r As Long
  Dim IPic As IPicture
  Dim IID_IDispatch As GUID
  With IID_IDispatch
    .Data1 = &H20400
    .Data4(0) = &HC0
    .Data4(7) = &H46
  End With
  Set Image = CreateObject("csImageFileTrial.Manage")
  Image.NewImage 200, 100, "ff0000"
  Image.TextOpaque = False
  Image.TextSize = 20
  Image.Text 40, 35, "Sample Text"
  Image.Rectangle 20, 20, 180, 80
  With Pic
    .Size = Len(Pic)
    .Type = vbPicTypeBitmap
    .hBmp = Image.BMPHandle
  End With
  r = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)
  Picture1.Picture = IPic
End Sub

Most of this code involves the use of the "OleCreatePictureIndirect" API call to create a bitmap that can be displayed in the picture box. csImageFile is able to export the bitmap handle using the BMPHandle method. Note that the csImageFile object is created using the CreateObject command:

Dim Image As manage
Set Image = CreateObject("csImageFileTrial.Manage")

With the full version of the component use "csImageFile.Manage".

A major drawback with using csImageFile in a VB application is the fact that the DLL needs to be distributed with each application. Our standard licence terms do not allow reselling of the DLL. For "in-house" applications this is not an issue as the multiple server licence allows for any number of installations within a single company or organisation. The single server licence, allows for one installation. If you want to distribute csImageFile as part of an application contact us for prices and terms. Our ActiveX control, csXImage, is intended for distribution. For more on this - Click Here.

Cookies

This site uses cookies for functionality, traffic analysis and for targeted advertising. Click the Accept button to accept our Cookie Policy. The Cookie Policy page offers configuration for a reduced set of cookies for this site.