![]() |
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
(PureBasic) Simple AI Image GenerationSee more AI ExamplesCreate an image by providing a text description.Note: This example requires Chilkat v11.4.0 or greater.
IncludeFile "CkAi.pb" IncludeFile "CkBinData.pb" IncludeFile "CkJsonObject.pb" Procedure ChilkatExample() success.i = 0 ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. ai.i = CkAi::ckCreate() If ai.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkAi::setCkProvider(ai, "openai") ; Use your provider's API key. CkAi::setCkApiKey(ai, "MY_API_KEY") ; Choose a model. CkAi::setCkModel(ai, "gpt-5") askParams.i = CkJsonObject::ckCreate() If askParams.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckUpdateString(askParams,"image.output_format","jpeg") CkJsonObject::ckUpdateString(askParams,"image.size","1024x1024") CkJsonObject::ckUpdateString(askParams,"image.quality","low") CkAi::ckSetAskParams(ai,askParams) CkAi::ckInputAddText(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::ckAsk(ai,"image") If success = 0 Debug CkAi::ckLastErrorText(ai) CkAi::ckDispose(ai) CkJsonObject::ckDispose(askParams) ProcedureReturn EndIf ; Get the image response data. bdImageData.i = CkBinData::ckCreate() If bdImageData.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkAi::ckGetOutputBd(ai,bdImageData) If success = 0 Debug CkAi::ckLastErrorText(ai) CkAi::ckDispose(ai) CkJsonObject::ckDispose(askParams) CkBinData::ckDispose(bdImageData) ProcedureReturn EndIf CkBinData::ckWriteFile(bdImageData,"c:/aaworkarea/out.jpg") Debug "Success." CkAi::ckDispose(ai) CkJsonObject::ckDispose(askParams) CkBinData::ckDispose(bdImageData) ProcedureReturn EndProcedure |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.