eDocEngine VCL
Create documents and reports in 18 formats
Compatibility
Delphi C++Builder

Fun With Delphi and Dynamic Image Creation

Fun at work with eDocEngine VCL.
By V. Subhash (German version)

Over the past month, I have been preparing a new help file for eDocEngine VCL. And, this was the first time I began using it. eDocEngine is a great component suite for Delphi/C++Builder developers to create text documents, spreadsheets, images, and clipboard content. The content creation tools in the product have their API but they support regular canvas operations that developers might already be familiar with.

While creating example code snippets for the help, I realized that the tool could be used to create all sorts of dynamic images. You want to plot the movement of the Dow Jones index on a line graph. Yessir, you can. However, I decided to do something else. I took a generic image of a protester from the Internet and decided to have some fun with it. Here is the image that I used as a template. (I scrubbed the original "This is my protest sign" message on the sign.)

Using the JPEG engine that comes with eDocEngine, I rendered this image on a "page" that was exactly the same size as the image. Then, I set about adding my own text over the protest sign.

Here is my code.

procedure TForm10.Button1Click(Sender: TObject);
var
  gtJPEGEngine1: TgtJPEGEngine;
  Image1: TBitmap;
begin

  // Load protest template image
  Image1 := TBitmap.Create;
  Image1.LoadFromFile('Input_Docs\protest.bmp');

  // Create a JPEG engine
  gtJPEGEngine1 := TgtJPEGEngine.Create(Nil);

  with gtJPEGEngine1 do begin
    Preferences.ShowSetupDialog := false;
    Preferences.OpenAfterCreate := true;
    MeasurementUnit :=  muPixels;

    // Set JPEG encoding settings
    PixelFormat := pf24bit;
    ProgressiveEncoding := true; // Web friendly
    Quality := 80;  // A nice tradeoff

    FileName := 'Output_Docs\Protest1.jpg';
    with Page do begin
      PaperSize := Custom;
      Width := 640;
      Height := 480;
    end;

    // Set font properties
    Font.Name := 'Comic Sans MS';
    Font.Size := 40;
    Font.Color := clRed;

    // Rotate text to suit the tilt of the sign
    SetTextRotation(7);

    BeginDoc; // Create image file
    // Render template image
    DrawImage(gtRect(0,0, 640, 480), TGraphic(Image1));
    // Render text over template
    TextOut(225,100, 'Stop');
    TextOut(225,200, 'Cartoon');
    TextOut(225,300, 'Violence');
    EndDoc;  // Save new image to file

    // Create protest image
    FileName := 'Output_Docs\Protest2.jpg';
    Font.Size := 28;
    Font.Color := clWebBlueViolet;
    SetTextRotation(5);
    BeginDoc;
    DrawImage(gtRect(0,0, 640, 480), TGraphic(Image1));
    TextOut(225,120, 'Save the');
    TextOut(230,220, 'WHALES!');
    TextOut(165,320, 'Collect all of them.');
    EndDoc;

    Image1.Free;
  end;
  Close;  // Exit form
end;

And, here is the output.

DISCLAIMER: Gnostice has no stand on cartoons or whaling. The template image was found on a site that deals with obscure protest signs.

---o0O0o---

Our .NET Developer Tools
XtremeDocumentStudio .NET

Multi-format document-processing component suite for .NET developers.

PDFOne .NET

A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

Our Delphi/C++Builder developer tools
XtremeDocumentStudio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

Our Java developer tools
XtremeDocumentStudio (for Java)

Multi-format document-processing component suite for Java developers.

PDFOne (for Java)

A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications.

Our Platform-Agnostic Cloud and On-Premises APIs
StarDocs

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2017 Gnostice Information Technologies Private Limited. All rights reserved.