PixeLook
Development Group

See also:

[Image analysis]

[Vector editor]

[IPL wrapper]

[AVI - demo]

[Samples]

[ ZL.DLL ]

Monitor page
for changes

it's private
powered by
ChangeDetection

 

1

Tutorial 1. How to create an image viewer                           Next

 

Viewer for fixed image

Start a new application (File/New/Application)

Drop the ZBitmapLink component  from the PixeLook component page  onto the main form of the application. In the Object Inspector set the following properties of the ZBitmapLink1 object:

    MappingMode = mmDisk

This property shows that you will use disk-based files. To use memory-based files you should create them at run-time

    Active = True

This property specifies that the image will be opened as soon as the FileName property is not empty.

    FileName = filename,

This property sets the file name of an image, where filename is the full path of any BMP image.

Drop the ZImageBox component  from the PixeLook component page onto the main form of the application. In the Object Inspector set the following property of the ZImageBox1 object:

    Align = alClient
    BitmapLink = ZBtmapLink1

The last property connects the image window and the image. From this moment, any change in the ZBitmapLink1 object (for example, image file name) will be reflected in the image window.

Run the application. You will see your image in the window.

 

Viewer for any image

Use the previous project. Leave the FileName property of the ZBitmapLink1 object empty.

Drop the OpenPictureDialog component from the Standard component page onto the main form of the application. Set the following property:

    Filter = Bitmaps (*.bmp)|*.bmp

Drop the MainMenu component  from the Standard component page onto the main form of the application. Create a File menu item and its OnClick event handler:

    procedure TForm1.File1Click(Sender: TObject);
    begin
      if OpenPictureDialog1.Execute then
      begin
       ZBitmapLink1.Sequence := false;
       ZBitmapLink1.FileName:=OpenPictureDialog1.FileName;
      end;
    end;

Run the application. Now you can open any image in your program.

Viewer for image sequences

Use the previous project. Add the following menu items to the main menu: Sequence,  Next, Prev, Play, First. Create the OnClick event handlers for these menu items:

    procedure TForm1.Sequence1Click(Sender: TObject);
    var Dir,Mask: string;
    begin
      if SelectDirectory('Select directory','',Dir) then
      begin
       Mask:= InputBox('File name mask', 'Mask', '*.bmp');
       ZBitmapLink1.Sequence := true;
       ZBitmapLink1.FileName := Dir+'\'+Mask;
      end;
    end;

    procedure
    TForm1.Next1Click(Sender: TObject);
    begin
      ZBitmapLink1.SeqAction(saNext);
    end;

    procedure
    TForm1.Prev1Click(Sender: TObject);
    begin
      ZBitmapLink1.SeqAction(saPrev);
    end;

    procedure
    TForm1.Play1Click(Sender: TObject);
    begin
      if not ZBitmapLink1.Playing then
         Play1.Caption:='Stop'
      else
         Play1.Caption:='Play';
      ZBitmapLink1.SeqAction(saPlay);
    end;

    procedure
    TForm1.Stop1Click(Sender: TObject);
    begin
      ZBitmapLink1.SeqAction(saFirst);
    end;

Run the program. Now, using the Sequence menu item, you can open any sequence of BMP files. After choosing this menu item, the standard ‘Select directory’ Windows dialog appears. You should select a directory where an image sequence is stored. After that, a new dialog appears where you should select the mask of file names that you want to visualize as a sequence. For example, it could be ‘img*.bmp’. After pressing ‘Ok’ the first image of the sequence appears. Using the other menu items you can navigate through the sequence.

Suppose we want to show the current file name in a status string. Drop the TStatusBar component onto the application form and create the ZBitmapLink1.OnChange event handler:

    procedure TForm1.ZBitmapLink1Change(Sender: TObject);
    begin
      if ZBitmapLink1.Bitmap<>nil then
         StatusBar1.SimpleText:=ZBitmapLink1.CurrentFileName;
    end;

Now, when you go through the sequence, you will see the corresponding file names in the status bar.

Using lenses for image viewing

This part of the tutorial shows how to use a powerful concept of the PixeLook library - lenses. Change the Align property of the ZImageBox1 component:

    Align = alLeft

Resize ZImageBox1 so that it occupies half of the form. Drop the TSplitter component from the Additional palette page. Drop another TZImageBox component onto the remaining part of the form and set the alignment:

    ZImageBox2.Align = alLeft

Declare that ZImageBox2 is a lens of ZImageBox1:

    ZImageBox1.Lens = ZImageBox2

Set the zoom level of the lens:

    ZImageBox2.Image.Zoom = 3

which means that each pixel of the original image will be zoomed in 2*2*2 = 8 times.

Now you can run the program and open either an image or an image sequence. The lens will follow the mouse and visualize a zoomed portion of the image under the mouse.

How to open many image formats in your program

For this purpose we will use the GraphicsEx library from the Delphi Gems website. We will also use the ZGraphicEx.pas unit from the Misc directory of the PixeLook download package. Include it in the uses list:

    uses ..., ZGraphicsEx;

Create the ZBitmapLink1.OnOpenImage event handler:

    procedure TForm1.BitmapLink1OpenImage(Sender: TObject; BM: TZDataBitMap; FileName: String);
    begin
       if OpenImageEx(FileName,’temp.bmp’) then
         BM.Open(mmDisk,’temp.bmp’);
    end;

This event occurs before the TZBitmapLink opens an image. So we can insert our own procedures to import an image format different from BMP. Such a procedure, namely OpenImageEx, is implemented in the ZGraphicsEx unit. It converts an image of any format to BMP. In the above case it converts FileName image to ‘temp.bmp’. If conversion was successful, then TZBitmapLink’s image (passed via the BM parameter) opens the file ‘temp.bmp’ file. Do not forget to include ZBitmap and ZDataBitmap files in the uses list.

Clear the OpenPictureDialog1.Filter property to allow all registered formats to appear in the dialog.

That is all. Now you can open more than 40 image formats in your program, in both single and sequence modes.

 

[Home] [News] [Features] [Components] [Screenshots] [Tutorials] [Download] [Order] [Contact us]

© Copyright PixeLook Development Group, 2002-2003. All rights reserved

Delphi™ is registered trademark of Borland Software Corporation.
Intel and Pentium are registered trademark of Intel Corporation.
PhotoShop is a trademark of Adobe Systems Inc.
All other trademarks are the property of their respective owners