![| Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/pexels-pavel-danilyuk-8438966-3449080-scaled.jpg?resize=1140%2C694&ssl=1)
![How to use the DeepAI service in the Delphi app | Embarcadero RAD Studio Delphi C++Builder Blogs how to use the deepai service in the delphi app](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/How-to-use-the-DeepAI-service-in-the-Delphi-app-5309120.jpg?resize=300%2C195&ssl=1)
Today AI technologies boast high popularity and demand in many spheres of our life. For example, AI is used for face identification on smartphones. On social networks, we have the possibility to add different effects on photos (AR, collages, etc.). AI tools allow users to identify different objects. They are used in video surveillance systems for identifying cars, people, animals, and all sorts of other useful capabilities.
In this article, we will analyze a popular multifunctional AI service, DeepAI, and show you how easy it is to use it in your cross platform apps. With the DeepAI service, users can enjoy all the capabilities and benefits of AI via a simple and straight-forward API. One DeepAI feature allows colorizing your old black-and-white photos. It can also identify some undesirable items in the photo (like weapons, etc) and provides many other possibilities.
We will show how you can easily use the DeepAI service in your Delphi FMX cross platform apps. To work with images, we suggest using the Image Colorization API.
![Main Page Image Colorization API | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps Main Page Image Colorization API](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/1-4165923-5445386.jpg?resize=750%2C398&ssl=1)
Table of Contents
What does the DeepAI Image Colorization API do?
This service for colorizing black-and-white photos is ensured by the API for work with images.
![Description of Image Colorization API | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps Description of Image Colorization API](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/2-8768674.png?resize=703%2C246&ssl=1)
For working via the API, it is necessary to send a POST
request to the DeepAI server and to provide the path to the file of a black-and-white image and an API key. It is also required to use a link for connecting to the DeepAI Image Colorization API service.
![Description how to use Image Colorization API in your apps | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps Description how to use Image Colorization API in your apps](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/3-4727669.png?resize=696%2C160&ssl=1)
Get valuable insights on how clean and sharp photos are when implementing an image upscale using DeepAI’s Super Resolution API.
How do I get a DeepAI API key?
For getting an API key, you have to sign up. This process is rather simple. It is necessary to click SIGNUP.
![How to signup | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps How to signup](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/4-1813520.jpg?resize=750%2C155&ssl=1)
Then you have to enter the user name, email, and password.
![Signup dialog | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps Signup dialog](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/5-4190570.jpg?resize=623%2C542&ssl=1)
After that, you will receive a link for account verification on your email. You will just have to follow the link.
![DeepAI API key | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps DeepAI API key](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/6-2421614.jpg?resize=750%2C208&ssl=1)
You need to copy the received API key and save it for further use in the FMX Delphi app.
You will also have to add bank card details (card number, the date of expiration, CVV) for correct interaction with the service (the tab Billing). DeepAI offers a free trial limit of 5 dollars.
![Billing information | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps Billing information](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/7-2063534.jpg?resize=750%2C393&ssl=1)
How to use DeepAI in a Delphi FMX cross platform App
As an example, we will send a black-and-white photo from our Delphi FMX app with the use of the POST
request to the server and will get a response in the JSON format that keeps the URL link leading to the processed colorful image.
In Delphi, for working with the DeepAI server, we can use some standard components TNetHttpRequest
and TNetHttpClient
. We have to assign the value of the current TNetHttpClient component (NetHttpClient1) to the Client field in the TNetHttpRequest component. We also need to assign the value “POST” to the MethodString field.
![NetHttpRequest and NetHttpClient components settings | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps NetHttpRequest and NetHttpClient components settings](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/8-6874990.jpg?resize=750%2C400&ssl=1)
How do I display the DeepAI image colorization results in a Delphi cross platform app?
We will use the standard component TImage for showing the original black-and-white image in the FMX app.
![TImage component for black and white image | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps TImage component for black and white image](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/9-8883193.jpg?resize=750%2C388&ssl=1)
For showing the processed colorful image to a user with the help of the REST of the DeepAI service, we also have to use the standard component TImage.
![TImage component for black and color image | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps TImage component for black and color image](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/10-6896976.jpg?resize=750%2C410&ssl=1)
For showing the JSON reply from the server in the Delphi FMX app, we will use the standard component TMemo (the tab Standard).
![TMemo component for keeping JSON response | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps TMemo component for keeping JSON response](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/11-1256290.jpg?resize=750%2C395&ssl=1)
For sending the parameters via the POST request to the server, such as the API key, the path to our black-and-white image on the computer, we should use the following variables.
Sending the DeepAI API request to the server
The variable (object) of the TName ValuePair header class will be used for sending our API key REST to the DeepAI server.
![TNameValue variable containing API key | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps TNameValue variable containing API key](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/12-5665461.jpg?resize=750%2C210&ssl=1)
The LMultiPartFormData object of the TMultipartFormData class is used for sending our black-and-white image following its path on the computer. A line variable path saves the path to our image file.
The path to the image differs on MSWindows and Android. That’s why conditional compilation is applied for these platforms.
During the compilation for MSWindows, our image file is stored on the C disk (c:Einstein.jpeg).
On Android, the image file will be stored in the internal memory of the smartphone in the Pictures folder.
![Black and white image path on Windows and Android | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps Black and white image path on Windows and Android](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/13-4444234.jpg?resize=722%2C337&ssl=1)
For loading the original black-and-white image to the TImage component, the LoadFromFile method is used. As a parameter, it takes a variable path.
The line variable path stores the name and the path to the image file.
![TImage components LoadFromFile method | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps TImage components LoadFromFile method](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/14-3352808.jpg?resize=717%2C110&ssl=1)
For executing the POST request and sending all the necessary data (a path to the image file, an API key) to the server, we need to use the POST method of the NetHTTPRequest1 component.
![TNetHttpRequest components POST method | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps TNetHttpRequest components POST method](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/15-8447509.jpg?resize=750%2C85&ssl=1)
The method receives a link for connecting to the server, the LMultiPartFormData object that stores the path to the image file, the LMS object of the TMemoryStream class and the header variable with the API key.
![TNetHttpRequest components POST method input parameters description | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps TNetHttpRequest components POST method input parameters description](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/16-7257114.jpg?resize=750%2C85&ssl=1)
The LMS object is used for saving the reply received from the server in a JSON format.
![TMemoryStream variable | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps TMemoryStream variable](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/18-1423477.jpg?resize=750%2C280&ssl=1)
The received JSON reply from the server will be displayed in TMemo with the help of the LoadFromStream method.
![TMemo components LoadFromStream method | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps TMemo components LoadFromStream method](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/19-6243126.jpg?resize=750%2C200&ssl=1)
The JSON response from the server includes the URL link to the file of the processed colorful image (theoutput_url parameter).
![JSON response from DeepAI server with url link to color image | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps JSON response from DeepAI server with url link to color image](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/21-3011853.jpg?resize=750%2C112&ssl=1)
How to parse the DeepAI API JSON results into an image?
For loading a colorful image, it is necessary to get the URL link from the JSON reply from the DeepAI server via parsing.
For reply parsing, we should use the JSON object of the TJSONObject class.
As a result of parsing the JSON reply from the server, we will get the URL link and save it in the line variable ColorizedImagePath.
![Parsing JSON response | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps Parsing JSON response](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/22-9655510.jpg?resize=750%2C185&ssl=1)
For downloading a colorful image from the server, we need to use the GET method of the TNetHttpClient component.
![TNetHttpClient GET method for color image downloading to TMemoryStream object LResponse | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps TNetHttpClient GET method for color image downloading to TMemoryStream object LResponse](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/23-3696101.jpg?resize=750%2C233&ssl=1)
The GET method accepts the URL link of the colorful image in the server and the object of the TMemoryStream LResponse class. In our case, LResponse gets the colorful image from the server for its further display in TImage.
![TMemoryStream object description | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps TMemoryStream object description](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/24-6084332.jpg?resize=750%2C375&ssl=1)
For loading and displaying a colorful image, we will use the method of the TImage LoadFromStream component.
![TImage components LoadFromStream method for color image showing to a user | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps TImage components LoadFromStream method for color image showing to a user](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/25-9240978.jpg?resize=750%2C202&ssl=1)
Is there a Delphi example of using DeepAI to colorize images?
Here is some example Delphi program code of sending a request to DEEPAI and then loading the results into an image.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
procedure TForm1.Button1Click(Sender: TObject); begin TTask.Run( procedure var LMultipartFormData: TMultipartFormData; LMS: TMemoryStream; header: TNameValuePair; Json: TJSONObject; begin LMultipartFormData := TMultipartFormData.Create; header := TNameValuePair.Create(‘api-key’, ‘5a84f646-474f-4b86-ab69-a7a5ef0ad537’); {$IFDEF ANDROID} path := TPath.Combine(TPath.GetSharedPicturesPath, ‘Einstein.jpeg’); LMultipartFormData.AddFile(‘image’, path, ‘image/*’); Image1.Bitmap.LoadFromFile(path); {$ENDIF} {$IFDEF MSWINDOWS} path := ‘c:Einstein.jpeg’; LMultipartFormData.AddFile(‘image’, path, ‘application/octet-stream’); Image1.Bitmap.LoadFromFile(path); {$ENDIF} LMS := TMemoryStream.Create; NetHTTPRequest1.Post(‘https://api.deepai.org/api/colorizer’, LMultipartFormData, LMS, [header]); TThread.Synchronize(nil, procedure begin Memo1.Lines.LoadFromStream(LMS); TabControl1.GotoVisibleTab(1) end); Json := TJSONObject.ParseJSONValue(Memo1.Text) as TJSONObject; TThread.Synchronize(nil, procedure begin ColorizedImagePath := Json.GetValue(‘output_url’).Value; end); LMS.Free; LMultipartFormData.Free; end); end; procedure TForm1.Button2Click(Sender: TObject); begin Label2.Text := ColorizedImagePath; if NetHTTPClient1.Tag = NOT_BUSY then begin NetHTTPClient1.Tag := BUSY; TTask.Run( procedure var LResponse: TMemoryStream; begin LResponse := TMemoryStream.Create; try NetHTTPClient1.Get(ColorizedImagePath, LResponse); TThread.Synchronize(nil, procedure begin Image2.Bitmap.LoadFromStream(LResponse); end); finally LResponse.Free; NetHTTPClient1.Tag := NOT_BUSY; TabControl1.GotoVisibleTab(2) end; end); end; end; |
Are there any special considerations for Delphi Android apps when using DeepAI?
For the correct functioning of the Delphi FMX app on the Android platform, we need to install permissions for access to smartphone memory and internet connection.
Check out how these speech services by Google could be vital for the success of your business operations.
![Access to internet permission on Android | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps Access to internet permission on Android](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/27-7296251.jpg?resize=716%2C494&ssl=1)
![Write to external storage permission on Android | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps Write to external storage permission on Android](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/28-9043665.jpg?resize=714%2C521&ssl=1)
Let’s test the work of our Embarcadero Delphi FMX app on the MSWindows and Android platforms. Let’s send a black-and-white picture and get a processed colorful image from the DeepAI server.
![Original black and white image | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps Original black and white image](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/30-6907238.jpg?resize=481%2C489&ssl=1)
![JSON response from DeepAI | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps JSON response from DeepAI](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/31-9919540.jpg?resize=482%2C490&ssl=1)
![Color image from DeepAI server | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps Color image from DeepAI server](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/32-7497105.jpg?resize=478%2C486&ssl=1)
![Original black and white image 2 | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps Original black and white image 2](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/33-5274308.jpg?resize=479%2C487&ssl=1)
![JSON response from DeepAI 2 | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps JSON response from DeepAI 2](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/34-6938284.jpg?resize=483%2C491&ssl=1)
![Color image from DeepAI server 2 | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps Color image from DeepAI server 2](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/35-3018902.jpg?resize=483%2C491&ssl=1)
![Original black and white image 3 | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps Original black and white image 3](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/36-1273086.jpg?resize=494%2C502&ssl=1)
![JSON response from DeepAI 3 | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps JSON response from DeepAI 3](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/37-9157376.jpg?resize=497%2C505&ssl=1)
![Color image from DeepAI server 3 | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps Color image from DeepAI server 3](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/38-3305001.jpg?resize=497%2C505&ssl=1)
What does the Delphi Android FMX DeepAI cross platform example results look like?
Let’s test the work of the FMX app on an Android device.
![JSON response from DeepAI Android device | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps JSON response from DeepAI Android device](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/39-4717459.jpg?resize=338%2C676&ssl=1)
![Original black and white image Android device | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps Original black and white image Android device](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/40-4847038.jpg?resize=338%2C676&ssl=1)
![Color image from DeepAI server Android device | Embarcadero RAD Studio Delphi C++Builder Blogs How To Use The DeepAI Service In Your Cross Platform Apps Color image from DeepAI server Android device](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/03/41-1048409.jpg?resize=338%2C675&ssl=1)
Watch step by step guide on the Softacom Youtube channel
This article was written by Softacom, one of our excellent Embarcadero Tech Partners.
You can read more about Softacom’s AI implementation services by clicking this link: https://softacom.com/services/artificial_intelligence_implementation_with_delphi/
Why not download a free trial of Embarcadero Delphi today and try the DeepAI example for yourself?
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition