有了 Vertex AI 中的 Gemini 和 Imagen,應用程式開發人員就能使用 Google 最先進的圖像生成式 AI 功能。應用程式開發人員可以運用 Vertex AI 上的 Gemini 和 Imagen,建構新一代 AI 產品,借助 AI 生成功能,在幾秒內將使用者的想像轉化為高品質的視覺素材。
有了 Gemini 和 Imagen,你可以:
- 僅使用文字提示生成新穎圖像 (文字轉圖像 AI 生成)。
- 使用您定義的遮罩區域,編輯或擴展上傳或生成的圖像。
- 放大現有、生成或編輯的圖片。
前一張圖片的提示
這些圖片是使用一般 Imagen 3 圖像生成模型 (imagen-3.0-generate-002) 和下列提示生成:
- 黏土動畫場景。中景:年長婦女。她穿著飄逸的服裝,她站在綠意盎然的花園中,用橘色灑水壺澆花
- 此圖像採用數位單眼相機拍攝,並使用偏光濾鏡。土耳其卡帕多奇亞的獨特岩層地貌,上空有兩顆熱氣球。這些氣球的顏色和圖案與下方風景的土色調形成美麗的對比。這張相片捕捉了享受這類體驗時的冒險感。
- 在長滿野花的田野中,一隻小藍鳥停在木製機器人伸出的手上,機器人身上爬滿開花的藤蔓,顯得飽經風霜,但仍靜靜佇立。數位卡通,暖色調和柔和線條。後方聳立著高聳的懸崖和瀑布。
- 畫面顯示一隻手拿著小小的黏土鳥模型,另一隻手則拿著塑形工具,正在雕塑模型。你可以看到雕塑家的圍巾。雙手沾滿黏土粉塵。微距數位單眼相機圖片,突顯紋理和工藝。
- 桌上擺著一個舊藍色玻璃花瓶,裡面插著一大束色彩繽紛的花朵。前方有一朵美麗的牡丹花,周圍環繞著各種其他花朵,例如玫瑰、百合、雛菊、蘭花、水果、莓果、綠葉。背景為深灰色。荷蘭黃金時代風格的油畫。
- 單一漫畫格:男孩和父親坐在草地上,凝視日落。男孩的嘴巴指向一個對話泡泡,上面寫著:太陽會再次升起。柔和的 1990 年代末期風格
快速入門導覽課程:使用 Imagen 透過文字提示生成圖像
你只需要輸入描述性文字,就能生成新穎的圖像。以下範例顯示簡化的圖片生成案例,但您可以使用其他參數,根據需求調整生成的圖片。
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles. -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles. -
為環境設定驗證機制。
Select the tab for how you plan to use the samples on this page:
Python
如要在本機開發環境中使用本頁面的 Python 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。
安裝 Google Cloud CLI。
若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI。
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
詳情請參閱 Google Cloud 驗證說明文件中的「 為本機開發環境設定 ADC」。
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
安裝 Google Cloud CLI。
若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI。
詳情請參閱 Google Cloud 驗證說明文件中的「使用 REST 進行驗證」。
使用下列範例生成圖片:
Python
REST
-
設定環境變數:
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT # Replace with your Google Cloud project export GOOGLE_CLOUD_LOCATION=us-central1 # Replace with the appropriate location for your project
-
執行以下指令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ "https://${GOOGLE_CLOUD_LOCATION}-aiplatform.googleapis.com/v1/projects/${GOOGLE_CLOUD_PROJECT}/locations/${GOOGLE_CLOUD_LOCATION}/publishers/google/models/imagen-4.0-generate-preview-05-20:predict" -d \ $'{ "instances": [ { "prompt": "a cat reading a book" } ], "parameters": { "sampleCount": 1 } }'
模型會傳回 base64 圖片位元組物件。
詳情請參閱 Imagen Generate images API。
模型版本
你可以使用多種圖片生成模型。詳情請參閱 Gemini 模型或 Imagen 模型。
試試更多範例
如需使用 Imagen 的完整 Jupyter 筆記本教學課程清單,請參閱 Vertex AI 的生成式 AI 教戰手冊。
何時該使用 Vertex AI 的 Gemini 或 Imagen
除了使用 Gemini 內建的圖像生成功能,你也可以存取專門的圖像生成模型 Imagen。
屬性 Gemini Image Imagen 4 優勢 預設建議。
無與倫比的彈性、情境理解能力,以及簡單易用的無遮罩編輯功能。獨家支援多輪對話式編輯。最佳品質/延遲 可用性 正式發布版 正式發布版 延遲時間 較高。進階功能需要更多運算資源。 低。針對近乎即時的效能進行最佳化。 費用 以權杖為基礎的定價。 執行特定工作時,可有效節省成本。 建議工作 - 生成文字和圖片夾雜的內容,讓文字和圖片完美融合。
- 輸入一則提示,即可結合多張圖片的創意元素。
- 對圖片進行高度精確的編輯、使用簡單的語言指令修改個別元素,以及反覆處理圖片。
- 將某張圖片的特定設計或紋理套用至另一張圖片,同時保留原始主體的形狀和細節。
- 圖片品質、擬真度、藝術細節或特定風格 (例如印象派和動漫) 是首要考量。
- 融入品牌、風格,或生成標誌和產品設計。
- 生成進階拼字或排版。
Gemini 是生成圖像的首選模型。如要處理進階用途或需要最佳圖片品質,請選擇 Imagen 4 Ultra (請注意,一次只能生成一張圖片)。
後續步驟
請使用下列連結查看功能說明文件。
提示指南
操作說明:生成圖片
參考:生成圖片圖片來源:所有圖片皆使用 Vertex AI 的 Imagen 生成。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-12-04 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-12-04 (世界標準時間)。"],[],[]]





