![]() |
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
(DataFlex) AI Modify Existing Image with Text PromptSee more AI ExamplesUses an AI text prompt and uploaded image data to modify an existing image and receive the modified output.Note: This example requires Chilkat v11.4.0 or greater.
Use ChilkatAx-win32.pkg Procedure Test Boolean iSuccess Variant vBdImageData Handle hoBdImageData Handle hoAi Variant vAskParams Handle hoAskParams String sTemp1 Move False To iSuccess // 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. Get Create (RefClass(cComChilkatBinData)) To hoBdImageData If (Not(IsComObjectCreated(hoBdImageData))) Begin Send CreateComObject of hoBdImageData End Get ComLoadFile Of hoBdImageData "qa_data/jpg/kid_blue_coat.jpg" To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoBdImageData To sTemp1 Showln sTemp1 Procedure_Return End Get Create (RefClass(cComChilkatAi)) To hoAi If (Not(IsComObjectCreated(hoAi))) Begin Send CreateComObject of hoAi End Set ComProvider Of hoAi To "openai" // Use your provider's API key. Set ComApiKey Of hoAi To "MY_API_KEY" // Choose a model. Set ComModel Of hoAi To "gpt-5" Get Create (RefClass(cComChilkatJsonObject)) To hoAskParams If (Not(IsComObjectCreated(hoAskParams))) Begin Send CreateComObject of hoAskParams End Get ComUpdateString Of hoAskParams "image.output_format" "jpeg" To iSuccess Get pvComObject of hoAskParams to vAskParams Get ComSetAskParams Of hoAi vAskParams To iSuccess Get pvComObject of hoBdImageData to vBdImageData Get ComInputAddImageData Of hoAi vBdImageData "" To iSuccess Get ComInputAddText Of hoAi "Modify the image by replacing the blue coat with a Metallica T-shirt." To iSuccess // Give the AI some time (2 minutes). Set ComIdleTimeoutMs Of hoAi To 120000 // Ask the AI for image output. Get ComAsk Of hoAi "image" To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoAi To sTemp1 Showln sTemp1 Procedure_Return End // Get the image response data.; Get pvComObject of hoBdImageData to vBdImageData Get ComGetOutputBd Of hoAi vBdImageData To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoAi To sTemp1 Showln sTemp1 Procedure_Return End Get ComWriteFile Of hoBdImageData "c:/aaworkarea/out.jpg" To iSuccess Showln "Success." // ------------------------------- // Sample Input: // ------------------------------- // |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.