![]() |
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
(Unicode C) Simple AI Image GenerationSee more AI ExamplesCreate an image by providing a text description.Note: This example requires Chilkat v11.4.0 or greater.
#include <C_CkAiW.h> #include <C_CkJsonObjectW.h> #include <C_CkBinDataW.h> void ChilkatSample(void) { BOOL success; HCkAiW ai; HCkJsonObjectW askParams; HCkBinDataW bdImageData; success = FALSE; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. ai = CkAiW_Create(); CkAiW_putProvider(ai,L"openai"); // Use your provider's API key. CkAiW_putApiKey(ai,L"MY_API_KEY"); // Choose a model. CkAiW_putModel(ai,L"gpt-5"); askParams = CkJsonObjectW_Create(); CkJsonObjectW_UpdateString(askParams,L"image.output_format",L"jpeg"); CkJsonObjectW_UpdateString(askParams,L"image.size",L"1024x1024"); CkJsonObjectW_UpdateString(askParams,L"image.quality",L"low"); CkAiW_SetAskParams(ai,askParams); CkAiW_InputAddText(ai,L"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 = CkAiW_Ask(ai,L"image"); if (success == FALSE) { wprintf(L"%s\n",CkAiW_lastErrorText(ai)); CkAiW_Dispose(ai); CkJsonObjectW_Dispose(askParams); return; } // Get the image response data. bdImageData = CkBinDataW_Create(); success = CkAiW_GetOutputBd(ai,bdImageData); if (success == FALSE) { wprintf(L"%s\n",CkAiW_lastErrorText(ai)); CkAiW_Dispose(ai); CkJsonObjectW_Dispose(askParams); CkBinDataW_Dispose(bdImageData); return; } CkBinDataW_WriteFile(bdImageData,L"c:/aaworkarea/out.jpg"); wprintf(L"Success.\n"); CkAiW_Dispose(ai); CkJsonObjectW_Dispose(askParams); CkBinDataW_Dispose(bdImageData); } |
||||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.