Delphi DLL
Delphi DLL
AI Modify Existing Image with Text Prompt
See more AI Examples
Uses an AI text prompt and uploaded image data to modify an existing image and receive the modified output.Chilkat Delphi DLL Downloads
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;
bdImageData: HCkBinData;
ai: HCkAi;
askParams: HCkJsonObject;
begin
success := False;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// Load the data from an existing image.
bdImageData := CkBinData_Create();
success := CkBinData_LoadFile(bdImageData,'qa_data/jpg/kid_blue_coat.jpg');
if (success = False) then
begin
Memo1.Lines.Add(CkBinData__lastErrorText(bdImageData));
Exit;
end;
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');
CkAi_SetAskParams(ai,askParams);
CkAi_InputAddImageData(ai,bdImageData,'');
CkAi_InputAddText(ai,'Modify the image by replacing the blue coat with a Metallica T-shirt.');
// Give the AI some time (2 minutes).
CkAi_putIdleTimeoutMs(ai,120000);
// 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.;
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.');
// -------------------------------
// Sample Input:
// -------------------------------
//
// -------------------------------
// Sample Output:
// -------------------------------
//
CkBinData_Dispose(bdImageData);
CkAi_Dispose(ai);
CkJsonObject_Dispose(askParams);
end;