Ana içeriğe geç

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.

Animated workflow

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.

Host app

Prepare Prompt

Require a nonempty description of the images to generate.

AI service

Read Optional Limit

Use a positive provider maximum when available; otherwise request one image.

AI service → app

Load Optional Styles

Use a returned styleCode when the provider exposes styles; otherwise leave style empty.

Host app

Configure Task

Set the resolved count and style, plus optional size and language.

AI service

Create Task

Start generation and retain the task ID from onTaskCreated.

task created
Authoritative result

Receive Images

Use success, images, task ID, and error from the completion callback.

Optional capability metadata must not block generation: use one image and no explicit style when it is unavailable.

Ö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 AIGCServiceAPI protokolü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

AI ile geliştirin

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.
Resmî beceriyi görüntüle

API Reference

Framework

AIBudsAI.xcframework

Declaration

Swift
/// 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)

generateAIPhoto, fetchAigcStyles ve AIGCTaskConfig başvurularına bakın.

Görev Yapılandırması

ÖzellikAnlamı
styleAIGCStyleModel.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.
languageen-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
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)
}

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 = nil ile 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.