![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java JavaScript Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Delphi DLL) Simple AI Image GenerationSee more AI ExamplesCreate an image by providing a text description.Note: This example requires Chilkat v11.4.0 or greater.
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, BinData, Ai, JsonObject; ... procedure TForm1.Button1Click(Sender: TObject); var success: Boolean; ai: HCkAi; askParams: HCkJsonObject; bdImageData: HCkBinData; begin success := False; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. ai := CkAi_Create(); CkAi_putProvider(ai,'openai'); // Use your provider's API key. CkAi_putApiKey(ai,'MY_API_KEY'); // Choose a model. CkAi_putModel(ai,'gpt-5'); askParams := CkJsonObject_Create(); CkJsonObject_UpdateString(askParams,'image.output_format','jpeg'); CkJsonObject_UpdateString(askParams,'image.size','1024x1024'); CkJsonObject_UpdateString(askParams,'image.quality','low'); CkAi_SetAskParams(ai,askParams); CkAi_InputAddText(ai,'Generate a small, cute illustration of a gray tabby cat hugging a happy otter wearing an orange scarf'); // Ask the AI for image output. success := CkAi_Ask(ai,'image'); if (success = False) then begin Memo1.Lines.Add(CkAi__lastErrorText(ai)); Exit; end; // Get the image response data. bdImageData := CkBinData_Create(); success := CkAi_GetOutputBd(ai,bdImageData); if (success = False) then begin Memo1.Lines.Add(CkAi__lastErrorText(ai)); Exit; end; CkBinData_WriteFile(bdImageData,'c:/aaworkarea/out.jpg'); Memo1.Lines.Add('Success.'); CkAi_Dispose(ai); CkJsonObject_Dispose(askParams); CkBinData_Dispose(bdImageData); end; |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.