Tutorial: Photo Fun (page 1)

The beginner to programming may have already worked through my Family Tree project to get a feel for designing and coding a complete project. Now for some image fun – and a really useful application...

Manipulate your digital photographs with this complete project. Adjust the colours, convert them to monochrome or make positive prints from your film negatives. Combine images, melting them together or building them up from RGB separations. Dig out your red and blue spectacles and create your own stunning 3D images.

We use object orientated design so that you can add your own image manipulations with just a few lines of code.

Let's begin

Start with a new application (From the Lazarus menu, create a New... | Project | Application), adding the usual ActionList, MainMenu and Toolbar to the main form.

To display the image that the user will be working on, add an Image component. You notice that the Image does not have a ScrollBars property. Add this feature by first placing a ScrollBox on the form and then placing the Image inside this.

The Base Photo

With a rough design of the user-interface to help us visualise the project, it is time to start work on the non-visual objects which will contain the logic of the application.

Create a new File | New Unit and save it as “PhotoObjects”.

We will load our digital photographs into a “TBasePhoto” class, manipulate them and then display the output in the Image on the project main form.

Add a “RawImage” property of type TBitmap in TBasePhoto to store the unprocessed image. In the published section, add a “DisplayImage” property of type TImage. At run-time we use this to link to the Image component on the project main form.

The predefined PixelFormats of a TBitmap range from pf1bit to pf32bit. You can convert the image structure between these formats by setting this property. For simplicity we will just support the pf24bit and pf32bit formats for now now but this can easily be extended by using case statements.

Declare a “RedrawDisplay” procedure. Here we manipulate the pixels from the 'photo raw data to the display image. The manipulations we will

Next >

Webmaster Leslie Kaye     © 2021 All rights reserved.