Görsel Oluşturma
Metin isteminden bir veya daha fazla UIImage sonucu oluşturun. Sağlayıcı sınırları ve seçilebilir stiller isteğe bağlı yeteneklerdir; oluşturma görevi göndermenin ön koşulu değildir.
Image-generation task lifecycle
Prepare a prompt, use provider limits or styles when available, and fall back to the default task configuration when they are not exposed.
Ön Koşullar
AIBudsAISDK'yi başlatın, bir sağlayıcı seçin ve gerekiyorsa kimlik doğrulamayı tamamlayın.- Seçilen sağlayıcının
AIGCServiceAPIprotokolünü uyguladığını doğrulayın. - Oluşturulan görselleri gösterme, saklama ve paylaşmaya ilişkin uygulama politikasını tanımlayın.
AI desteğiyle uygulayın
Bu iş akışını AI ile uygulayın
Resmî “AIBuds AI ile Görsel Oluşturma” becerisini kullanarak iş akışını uygulamanıza uyarlayın.
https://docs-aibuds.github.io/tr/skills/generate-aibuds-ai-images adresini okuyup yönergeleri izleyin. Bu beceriyle “AIBuds AI ile Görsel Oluşturma” iş akışını iOS projesinde uygulayıp doğrulayın.API Reference
Framework
AIBudsAI.xcframework
Declaration
- Swift
- Objective-C
/// The available styles cached by the selected image-generation provider.
static var aigcStyles: [AIGCStyleModel]? { get }
/// The maximum number of images accepted in one task. A positive value can be
/// used to constrain the requested image count.
static var aigcMaxGenerateCount: Int { get }
/// Fetches styles supported by the selected provider.
public static func fetchAigcStyles(completion: ((_ styles: [AIGCStyleModel]?, _ error: NSError?) -> Void)? = nil)
/// Generates images from a text prompt and configuration.
/// - Parameters:
/// - prompt: The text prompt for image generation.
/// - config: Task configuration. Defaults to `.default`.
/// - onTaskCreated: Called with the provider task identifier.
/// - completion: Returns the task identifier, success flag, generated images,
/// and failure information.
public static func generateAIPhoto(prompt: String,
config: AIGCTaskConfig = .default,
onTaskCreated: ((_ taskId: String) -> Void)? = nil,
completion: ((
_ taskId: String?,
_ success: Bool,
_ images: [UIImage]?,
_ error: NSError?
) -> Void)? = nil)/// Styles cached by the selected image-generation provider.
@property(nonatomic, class, readonly, copy) NSArray<AIBudsAIGCStyleModel *> *_Nullable aigcStyles;
/// Maximum image count accepted by one provider task.
@property(nonatomic, class, readonly) NSInteger aigcMaxGenerateCount;
/// Fetches styles supported by the selected provider.
+ (void)fetchAigcStylesWithCompletion:(void (^ _Nullable)(NSArray<AIBudsAIGCStyleModel *> * _Nullable, NSError * _Nullable))completion;
/// Generates images from a text prompt and configuration.
+ (void)generateAIPhotoWithPrompt:(NSString * _Nonnull)prompt
config:(AIBudsAIGCTaskConfig * _Nonnull)config
taskCreated:(void (^ _Nullable)(NSString * _Nonnull))onTaskCreated
completion:(void (^ _Nullable)(NSString * _Nullable, BOOL, NSArray<UIImage *> * _Nullable, NSError * _Nullable))completion;generateAIPhoto, fetchAigcStyles ve AIGCTaskConfig başvurularına bakın.
Görev Yapılandırması
| Özellik | Anlamı |
|---|---|
style | AIGCStyleModel.styleCode tarafından döndürülen sağlayıcı stil kodu. Stil yoksa veya uygulama stil seçimi sunmuyorsa nil bırakın. |
imageCount | İstenen sayı. Varsayılan 1 değerini pozitif aigcMaxGenerateCount yoksa kullanın; aksi halde bildirilen sınırı aşmayın. |
imageSize | İsteğe bağlı pozitif genişlik ve yükseklik; nil sağlayıcının varsayılanını kullanır. |
language | en-US gibi istem dili; nil uygulama dilini kullanır, boş dize destekleniyorsa otomatik algılama ister. |
Kullanım Örnekleri
İsteğe Bağlı Sağlayıcı Yetenekleriyle Oluşturma
Uygulama stil seçimi sunmuyorsa fetchAigcStyles çağrısını atlayıp oluşturma yardımcısına nil verin. Aşağıdaki örnek stilleri yüklemeyi dener ancak liste boşsa veya istek başarısızsa da istemi gönderir.
- Swift
- Objective-C
let prompt = "A lightweight wearable assistant on a clean studio background"
func generate(styleCode: String?) {
let maximum = AIBudsAISDK.aigcMaxGenerateCount
let config = AIGCTaskConfig()
config.style = styleCode
config.imageCount = maximum > 0 ? min(2, maximum) : 1
config.language = "en-US"
AIBudsAISDK.generateAIPhoto(
prompt: prompt,
config: config,
onTaskCreated: { taskID in
DispatchQueue.main.async { showTask(id: taskID) }
},
completion: { taskID, success, images, error in
DispatchQueue.main.async {
guard success, let images, !images.isEmpty else {
if let error {
show(error)
} else {
print("The provider returned no images")
}
return
}
show(images: images, taskID: taskID)
}
}
)
}
AIBudsAISDK.fetchAigcStyles { styles, error in
// Style discovery is optional. A nil style uses the provider default.
let styleCode = error == nil ? styles?.first?.styleCode : nil
generate(styleCode: styleCode)
}NSString *prompt = @"A lightweight wearable assistant on a clean studio background";
void (^generate)(NSString *_Nullable) = ^(NSString *styleCode) {
NSInteger maximum = AIBudsAISDK.aigcMaxGenerateCount;
AIBudsAIGCTaskConfig *config = [[AIBudsAIGCTaskConfig alloc] init];
config.style = styleCode;
config.imageCount = maximum > 0 ? MIN(2, maximum) : 1;
config.language = @"en-US";
[AIBudsAISDK generateAIPhotoWithPrompt:prompt
config:config
taskCreated:^(NSString *taskID) {
dispatch_async(dispatch_get_main_queue(), ^{
[self showTaskID:taskID];
});
}
completion:^(
NSString *taskID, BOOL success, NSArray<UIImage *> *images, NSError *generationError) {
dispatch_async(dispatch_get_main_queue(), ^{
if (!success || images.count == 0) {
[self showError:generationError];
return;
}
[self showImages:images taskID:taskID];
});
}];
};
[AIBudsAISDK
fetchAigcStylesWithCompletion:^(NSArray<AIBudsAIGCStyleModel *> *styles, NSError *error) {
// Style discovery is optional. A nil style uses the provider default.
NSString *styleCode = error == nil ? styles.firstObject.styleCode : nil;
generate(styleCode);
}];Hata Yönetimi
Stil alma hatası veya oluşturma sınırının bulunmaması, oluşturma hatası değildir. style = nil ve imageCount = 1 değerlerine dönün; yetkili sonuç olarak oluşturma tamamlanma geri çağrısını kullanın.
Notlar
- Stil kodları ve pozitif azami sayılar isteğe bağlı sağlayıcı verileridir ve değişebilir; Demo değerlerini sabit kodlamayın.
- Boş stil listesi geçerlidir. Sağlayıcı varsayılanını kullanmak için istemi
style = nilile gönderin. - Görev oluşturuldu geri çağrısı, görsellerin başarıyla oluşturulduğu anlamına gelmez.
- Genel API şu anda görsel oluşturma ilerlemesini veya iptali sunmaz.