JPG and PNG inside a database (VCL)

In VCL applications we can easily add images to a database using the TDBImage component. But TDBImage only supports Bitmaps (BMP), and these uncompressed images take a lot of space and network bandwidth to store them. Fortunately it is quite easy to store compressed JPG and PNG images inside a database using TWICImage.

The TWICImage component has been available since Delphi 2010, and it uses Windows DirectX to determine and handle multiple image formats. It is actually an encapsulation of the Windows Imaging Component (WIC). We can use TWICImage to determine the type of an image and have it create a correct image format header. We can then save this header + image into a blob field.


procedure SavePictureFileToField(PictureFile: TFileName; Field: TBlobField);
var
  lWICImage: TWICImage;

begin
  lWICImage := TWICImage.Create;
  lWICImage.LoadFromFile(PictureFile);
  Field.Assign(lWICImage);
  lWICImage.Free;
end;

When we later read this image from the blob field, we use TWICImage to interpret the header and then assign it into a TImage.Picture for display.


procedure LoadPictureFromField(Field: TBlobField; Picture: TPicture);
var
  lWICImage: TWICImage;

begin
  if (Field.BlobSize > 0) then
  begin {Assume image}
    lWICImage := TWICImage.Create;
    lWICImage.Assign(Field);
    Picture.Assign(lWICImage);
    lWICImage.Free;
  end
  else {Empty}
  begin
    Picture.Assign(nil);
  end;
end;

And that’s all.

This code will work for any Delphi version starting from Delphi 2010.

Please note that if you are creating a multi-device / FireMonkey application you should not use TWICImage, the FireMonkey TImage and TImageControl both already handle all types of images just fine themselves and going through TWICImage would not be of benefit, in fact it would lock you into Windows.

Completed source code as a simple VCL SQLLite XE7 database application can be downloaded here: DBImage_JPG_PNG

Happy Birthday Delphi

Today Delphi turns 19. Last year has been pretty exciting for her, with XE4 iOS and XE5 with Android support. This year she’ll make some nice visits home in Windows VCL, with many good things to come.
Talking about VCL, don’t miss the Delphi Boot Camp which is all about VCL, here in the Netherlands:
http://www.barnsten.com/nl/events/details?events_id=90
Happy Birthday Delphi!

we made Tarte Tatin

we made Tarte Tatin

Auto start Delphi XE5 Android App after boot

In good ol’ DOS days we could start an application after boot by adding it to autoexec.bat. Under Windows you can add a program to startup using the registry or view startup programs with msconfig.

But how does this work under Android?

Automatically starting a Delphi XE5 Android app after the device has booted up can be done by creating a broadcast receiver that listens to the BOOT_COMPLETED broadcast intent.

This article descibes the steps necessary to create such a broadcast receiver with Delphi XE5:

  • create a new Delphi XE5 Android project
  • set uses permissions to receive boot completed
  • modify AndroidManifest.template.xml to let the Android system know you have a broadcast receiver
  • write some Java code
  • add it to the classes.dex
  • use this new classes.dex in your project
  • run the app on device

Continue reading here: Auto start Delphi XE5 Android App after boot

RAD Studio XE5 in Action Live – 10 oktober 2013

In dit heerlijk technische event laten we zien wat de mogelijkheden zijn van het nieuwe Delphi XE5. In de algemene presentatie gaan we in op de mogelijkheden voor multi-device development met Delphi. In de Android Deep Dive gaan we onder water kijken hoe het nieuwe Android development in Delphi XE5 werkt. Mis het niet!

Inschrijven kun je hier:
http://www.barnsten.com/nl/events/details?events_id=81

Delphi XE5 Sneak Peek: Threading op Android en iOS

Het is al bijna 7 september, dan pas kan ik echt alles laten zien van Delphi XE5 en Android. Maar in de tussentijd kon ik het niet laten om een kleine sneak preview te maken met de pre-release versie van Delphi XE5 met Android en iOS.

Delphi XE5 Sneak Peek: Threading op Android en iOS

Mocht je meer willen weten, kom dan naar het event in Leiden RAD Studio In Action Live! op zaterdag 7 september 2013. Mocht je dan niet kunnen, check dan de internationale events en “Talk live with dev experts on how to move from desktop to mobile development. Check here for locations http://embt.co/RADWorldTour

Als Delphi MVP mocht ik nu al wat laten zien van Delphi XE5, met dank aan Jim McKeeth van Embarcadero. Meer info over de komende release op http://embt.co/RADAndroid.