全部產品
Search
文件中心

Alibaba Cloud Model Studio:通義千問-影像編輯Qwen-Image-Edit

更新時間:Nov 13, 2025

通義千問-影像編輯模型(Qwen-Image-Edit)支援多圖輸入和多圖輸出,可精確修改圖內文字、增刪或移動物體、改變主體動作、遷移圖片風格及增強畫面細節。

快速開始

本樣本將示範如何使用qwen-image-edit-plus模型,根據3張輸入映像和提示詞,產生2張編輯後的映像。

輸入提示詞:圖1中的女生穿著圖2中的黑色裙子按圖3的姿勢坐下。

輸入映像1

輸入映像2

輸入映像3

輸出映像(多張映像)

image99

image98

image89

image100

imageout2

在調用前,您需要準備工作:擷取與配置 API Key,再配置API Key到環境變數(準備下線,併入配置 API Key)

如需通過SDK進行調用,請安裝DashScope SDK。目前,該SDK已支援Python和Java。

qwen-image-edit系列模型均支援傳入 1-3 張映像。在輸出方面,qwen-image-edit-plus 與qwen-image-edit-plus-2025-10-30支援產生 1-6 張映像,qwen-image-edit 僅支援產生1張映像。產生的映像URL連結有效期間為24小時,請及時通過URL下載映像到本地

Python

import json
import os
import dashscope
from dashscope import MultiModalConversation

# 以下為新加坡地區url,若使用北京地區的模型,需將url替換為:https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

# 模型支援輸入1-3張圖片
messages = [
    {
        "role": "user",
        "content": [
            {"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/thtclx/input1.png"},
            {"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/iclsnx/input2.png"},
            {"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/gborgw/input3.png"},
            {"text": "圖1中的女生穿著圖2中的黑色裙子按圖3的姿勢坐下"}
        ]
    }
]

# 新加坡和北京地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/zh/model-studio/get-api-key
# 若沒有配置環境變數,請用百鍊API Key將下行替換為:api_key="sk-xxx"
api_key = os.getenv("DASHSCOPE_API_KEY")

# 模型僅支援單輪對話,複用了多輪對話的介面
# qwen-image-edit-plus支援輸出1-6張圖片,此處以2張為例
response = MultiModalConversation.call(
    api_key=api_key,
    model="qwen-image-edit-plus",
    messages=messages,
    stream=False,
    n=2,
    watermark=False,
    negative_prompt=" ",
    prompt_extend=True,
    # 僅當輸出映像數量n=1時支援設定size參數,否則會報錯
    # size="1024*2048",
)

if response.status_code == 200:
    # 如需查看完整響應,請取消下行注釋
    # print(json.dumps(response, ensure_ascii=False))
    for i, content in enumerate(response.output.choices[0].message.content):
        print(f"輸出映像{i+1}的URL:{content['image']}")
else:
    print(f"HTTP返回碼:{response.status_code}")
    print(f"錯誤碼:{response.code}")
    print(f"錯誤資訊:{response.message}")
    print("請參考文檔:https://www.alibabacloud.com/help/zh/model-studio/error-code")

響應樣本

{
    "status_code": 200,
    "request_id": "121d8c7c-360b-4d22-a976-6dbb8bxxxxxx",
    "code": "",
    "message": "",
    "output": {
        "text": null,
        "finish_reason": null,
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "image": "https://dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com/xxx.png?Expires=xxx"
                        },
                        {
                            "image": "https://dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com/xxx.png?Expires=xxx"
                        }
                    ]
                }
            }
        ]
    },
    "usage": {
        "input_tokens": 0,
        "output_tokens": 0,
        "height": 1248,
        "image_count": 2,
        "width": 832
    }
}

Java

import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
import com.alibaba.dashscope.common.MultiModalMessage;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.List;

public class QwenImageEdit {

    static {
        // 以下為新加坡地區url,若使用北京地區的模型,需將url替換為:https://dashscope.aliyuncs.com/api/v1
        Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
    }
    
    // 新加坡和北京地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/zh/model-studio/get-api-key
    // 若沒有配置環境變數,請用百鍊 API Key 將下行替換為:apiKey="sk-xxx"
    static String apiKey = System.getenv("DASHSCOPE_API_KEY");

    public static void call() throws ApiException, NoApiKeyException, UploadFileException, IOException {

        MultiModalConversation conv = new MultiModalConversation();

        // 模型支援輸入1-3張圖片
        MultiModalMessage userMessage = MultiModalMessage.builder().role(Role.USER.getValue())
                .content(Arrays.asList(
                        Collections.singletonMap("image", "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/thtclx/input1.png"),
                        Collections.singletonMap("image", "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/iclsnx/input2.png"),
                        Collections.singletonMap("image", "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/gborgw/input3.png"),
                        Collections.singletonMap("text", "圖1中的女生穿著圖2中的黑色裙子按圖3的姿勢坐下")
                )).build();
        // qwen-image-edit-plus支援輸出1-6張圖片,此處以2張為例
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("watermark", false);
        parameters.put("negative_prompt", " ");
        parameters.put("n", 2);
        parameters.put("prompt_extend", true);
        // 僅當輸出映像數量n=1時支援設定size參數,否則會報錯
        // parameters.put("size", "1024*2048");

        MultiModalConversationParam param = MultiModalConversationParam.builder()
                .apiKey(apiKey)
                .model("qwen-image-edit-plus")
                .messages(Collections.singletonList(userMessage))
                .parameters(parameters)
                .build();

        MultiModalConversationResult result = conv.call(param);
        // 如需查看完整響應,請取消下行注釋
        // System.out.println(JsonUtils.toJson(result));
        List<Map<String, Object>> contentList = result.getOutput().getChoices().get(0).getMessage().getContent();
        int imageIndex = 1;
        for (Map<String, Object> content : contentList) {
            if (content.containsKey("image")) {
                System.out.println("輸出映像" + imageIndex + "的URL:" + content.get("image"));
                imageIndex++;
            }
        }
    }

    public static void main(String[] args) {
        try {
            call();
        } catch (ApiException | NoApiKeyException | UploadFileException | IOException e) {
            System.out.println(e.getMessage());
        }
    }
}

響應樣本

{
    "requestId": "46281da9-9e02-941c-ac78-be88b8xxxxxx",
    "usage": {
        "image_count": 2,
        "width": 1216,
        "height": 864
    },
    "output": {
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "image": "https://dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com/xxx.png?Expires=xxx"
                        },
                        {
                            "image": "https://dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com/xxx.png?Expires=xxx"
                        }
                    ]
                }
            }
        ]
    }
}

curl

以下為新加坡地區 URL ,若使用北京地區的模型,需將 URL 替換為:https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation

curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
    "model": "qwen-image-edit-plus",
    "input": {
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/thtclx/input1.png"
                    },
                    {
                        "image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/iclsnx/input2.png"
                    },
                    {
                        "image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/gborgw/input3.png"
                    },
                    {
                        "text": "圖1中的女生穿著圖2中的黑色裙子按圖3的姿勢坐下"
                    }
                ]
            }
        ]
    },
    "parameters": {
        "n": 2,
        "negative_prompt": " ",
        "prompt_extend": true,
        "watermark": false
    }
}'

響應樣本

{
    "output": {
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "image": "https://dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com/xxx.png?Expires=xxx"
                        },
                        {
                            "image": "https://dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com/xxx.png?Expires=xxx"
                        }
                    ]
                }
            }
        ]
    },
    "usage": {
        "width": 1248,
        "image_count": 2,
        "height": 832
    },
    "request_id": "bf37ca26-0abe-98e4-8065-xxxxxx"
}

通過URL下載映像到本地

# 需要安裝requests以下載映像: pip install requests
import requests


def download_image(image_url, save_path='output.png'):
    try:
        response = requests.get(image_url, stream=True, timeout=300)  # 設定逾時
        response.raise_for_status()  # 如果HTTP狀態代碼不是200,則引發異常
        with open(save_path, 'wb') as f:
            for chunk in response.iter_content(chunk_size=8192):
                f.write(chunk)
        print(f"映像已成功下載到: {save_path}")

    except requests.exceptions.RequestException as e:
        print(f"映像下載失敗: {e}")


image_url = "https://dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com/xxx.png?Expires=xxx"
download_image(image_url, save_path='output.png')
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
 
public class ImageDownloader {
    public static void downloadImage(String imageUrl, String savePath) {
        try {
            URL url = new URL(imageUrl);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setConnectTimeout(5000);
            connection.setReadTimeout(300000);
            connection.setRequestMethod("GET");
            InputStream inputStream = connection.getInputStream();
            FileOutputStream outputStream = new FileOutputStream(savePath);
            byte[] buffer = new byte[8192];
            int bytesRead;
            while ((bytesRead = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, bytesRead);
            }
            inputStream.close();
            outputStream.close();
 
            System.out.println("映像已成功下載到: " + savePath);
        } catch (Exception e) {
            System.err.println("映像下載失敗: " + e.getMessage());
        }
    }
 
    public static void main(String[] args) {
        String imageUrl = "http://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/xxx?Expires=xxx";
        String savePath = "output.png";
        downloadImage(imageUrl, savePath);
    }
}

效果概覽

多圖融合

輸入映像1

輸入映像2

輸入映像3

輸出映像

image83

image103

1

2

圖1中的女生戴著圖2中的項鏈,左肩挎著圖3中的包

主體一致性保持

輸入映像

輸出映像1

輸出映像2

輸出映像3

image5

image4

修改為藍底證件照,人物穿上白色襯衫,黑色西裝,打著條紋領帶

image6

人物穿上白色襯衫,灰色西裝,打著條紋領帶,一隻手摸著領帶,淺色背景

image7

人物穿著粗筆刷字型的“千問映像”的黑色衛衣,依靠在護欄邊,陽光照在髮絲上,身後是大橋和海

image12

image13

把這個空調放在客廳,沙發旁邊

image14

在空調出風口增加霧氣,一直到沙發上,並且增加綠葉。

image15

在上方增加白色的手寫體"自然新風 暢享呼吸"

草圖創作

輸入映像

輸出映像

image42

image43

產生一張映像,符合圖1所勾勒出的精緻形狀,並遵循以下描述:一位年輕的女子在陽光明媚的日子裡微笑著,她戴著一副棕色的圓形太陽鏡,鏡框上有豹紋圖案。她的頭髮被整齊地盤起,耳朵上佩戴著珍珠耳環,脖子上圍著一條帶有自色星星圖案的深藍色圍巾,穿著一件黑色皮夾克。

image44

產生一張映像,符合圖1所勾勒出的精緻形狀,並遵循以下描述:一位年老的老人朝著鏡頭微笑,他的臉上布滿皺紋,頭髮在風中淩亂,戴著一幅圓框的老花鏡。脖子上戴著一條破舊的紅色圍巾,上面有星星圖案。穿著一件棉衣。

文創產生

輸入映像

輸出映像

圖片 1

image23

讓這隻熊坐在月亮下(用白色背景上的淺灰彎月輪廓表示),抱著吉他,周圍漂浮著小星星和詩句氣泡,如“Be Kind”。

image22

將這個圖案印在一件T恤和一個手提紙袋上。一個女模特正在展示這些物品。這個女生還戴著一頂鴨舌帽,帽子上寫著"Be kind”。

image21

一個超逼真的1/7比例角色模型,設計為商業產品成品,放置在一台帶有白色拇指鍵盤的iMac電腦桌上。模型站在一個乾淨、圓形的透明亞克力底座上,沒有標籤或文字。專業的攝影棚燈光凸顯了雕刻細節。在背錄的iMac螢幕上,展示同一模型的ZBrush建模過程。在模型旁邊,放置一個封裝盒,前面帶有透明窗戶,僅顯示內部透明塑料殼,其高度略高於模型,尺寸合理以容納模型。

image

這隻熊穿著宇航服,伸出手指向遠方

image

這隻熊穿著華麗的舞裙,雙臂展開,做出優雅的舞蹈動作

image

這隻熊穿著運動服,手裡拿著籃球,單腿彎曲

根據深度圖產生映像

輸入映像

輸出映像

image36

image37

產生一張映像,符合圖1所勾勒出的深度圖,並遵循以下描述:在一條街邊的小巷中停放著一輛藍色的單車,背景中有幾株從石縫中長出來的雜草

image38

產生一張映像,符合圖1所勾勒出的深度圖,並遵循以下描述:一輛紅色的破舊的單車停在一條泥濘的小路上,背景是茂密的原始森林

根據關鍵點產生映像

輸入映像

輸出映像

image40

image41

產生一張映像,符合圖1所勾勒出的人體姿態,並遵循以下描述:一位身穿著漢服的中國美女,在雨中撐著油紙傘,背景是蘇州園林。

image39

產生一張映像,符合圖1所勾勒出的人體姿態,並遵循以下描述:一位男生,站在地鐵月台上,他頭上戴著一頂棒球帽,穿著T恤和牛仔褲。背後是飛馳而過的列車。

文字編輯

輸入映像

輸出映像

輸入映像

輸出映像

image

image

將拼字遊戲方塊上'HEALTH INSURANCE’ 替換為'明天會更好'

image

image

將便條上的短語“Take a Breather”更改為“Relax and Recharge”

輸入映像

輸出映像

image53

image45

將“Qwen-Image”換成黑色的滴墨字型

image46

將“Qwen-Image”換成黑色的手寫字型

image49

將“Qwen-Image”換成黑色的像素字型

image54

將“Qwen-Image”換成紅色

image57

將“Qwen-Image”換成藍紫漸層色

image59

將“Qwen-Image”換成糖果色

image63

將“Qwen-Image”材質換成金屬

image64

將“Qwen-Image”材質換成雲朵

image67

將“Qwen-Image”材質換成玻璃

增刪改及替換

能力

輸入映像

輸出映像

新增元素

image

image

在企鵝前方添加一個小型木製標牌,上面寫著“Welcome to Penguin Beach”。

刪除元素

image

image

刪除餐盤上的頭髮

替換元素

image

image

把桃子變成蘋果

人像修改

image

image

讓她閉上眼睛

姿態修改

image8

image9

她舉起雙手,手掌朝向鏡頭,手指張開,做出一個俏皮的姿勢

視角轉換

輸入映像

輸出映像

輸入映像

輸出映像

image

image

獲得正視視角

image

image

朝向左側

image

image

獲得後側視角

image

image

朝向右側

背景替換

輸入映像

輸出映像

image

image

將背景更改為海灘

image

將原圖背景替換為真實的現代教室情境,背景中央為一塊深綠色或墨黑色的傳統黑板,黑板表面用白色粉筆工整地寫著中文“通義千問”

老照片處理

能力

輸入映像

輸出映像

老照片修複及上色

image

image

修複老照片,去除劃痕,降低噪點,增強細節,高解析度,畫面真實,膚色自然,面部特徵清晰,無變形。

image31

image32

根據內容智能上色,使映像更生動

輸入說明

入參結構(messages)

輸入為messages數組,當前僅支援單輪對話,因此數組內有且只有一個對象,該對象包含rolecontent兩個屬性,其中role必須設定為usercontent需要同時包含image(1-3張映像)和text(一條編輯指令)。

"messages": [
    {
        "role": "user",
        "content": [
            { "image": "圖1的公網URL或Base64資料" },
            { "image": "圖2的公網URL或Base64資料" },
            { "image": "圖3的公網URL或Base64資料" },
            { "text": "您的編輯指令,例如:'圖1中的女生穿著圖2中的黑色裙子按圖3的姿勢坐下'" }
        ]
    }
]

映像輸入順序

在進行多影像編輯時,映像存在輸入順序,編輯指令需要與content中的映像的傳入順序相對應,如“圖1”、“圖2”,否則編輯效果會不符合預期。

輸入映像1

輸入映像2

輸出映像

image95

image96

5

將圖1中女生的衣服替換為圖2中女生的衣服

4

將圖2中女生的衣服替換為圖1中女生的衣服

映像輸入方式

公網URL

  • 提供一個公網可訪問的映像地址,支援 HTTP 或 HTTPS 協議。

  • 樣本值:https://xxxx/img.png

Base64編碼

將影像檔轉換為 Base 64 編碼字串,並按格式拼接:data:{mime_type};base64,{base64_data}

  • {mime_type}:映像的媒體類型,需與檔案格式對應。

  • {base64_data}:檔案經過 Base 64 編碼後的字串。

  • 樣本值:data:image/jpeg;base64,GDU7MtCZz...(樣本已截斷,僅做示範)

點擊查看圖片Base64編碼程式碼範例

import os
import base64
import mimetypes

# 格式為 data:{mime_type};base64,{base64_data}
def encode_file(file_path):
    mime_type, _ = mimetypes.guess_type(file_path)
    with open(file_path, "rb") as image_file:
        encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
    return f"data:{mime_type};base64,{encoded_string}"
        
        
# 調用編碼函數,請將 "/path/to/your/image.png" 替換為您的本地圖片檔案路徑,否則無法運行
image = encode_file("/path/to/your/image.png")

完整範例程式碼請參見Python SDK調用Java SDK調用

更多參數

可以通過以下可選參數調整產生效果:

  • n:指定輸出映像數量,預設值為1。qwen-image-edit-plusqwen-image-edit-plus-2025-10-30支援輸出1-6張圖片,qwen-image-edit僅支援輸出1張圖片。

  • negative_prompt(反向提示詞):描述不希望在畫面中出現的內容,如“模糊”、“多餘的手指”等,用於輔助最佳化產生品質。

  • watermark:是否在映像右下角添加 "Qwen-Image" 浮水印。預設值為 false。浮水印樣式如下:

    1

  • seed:隨機數種子。取值範圍是[0, 2147483647]。如果不提供,則演算法自動產生一個隨機數作為種子。使用相同的 seed 值可協助產生內容保持相對穩定。

以下可選參數僅qwen-image-edit-plusqwen-image-edit-plus-2025-10-30支援:

  • size:設定輸出映像的解析度,格式為寬*高字串,例如"1024*2048",寬和高的取值範圍均為[512, 2048]像素。此參數僅在輸出映像數量 n 為 1 時可用,否則將報錯。若不設定,輸出映像將保持與原圖相似的長寬比接近1024*1024解析度。

  • prompt_extend:是否開啟prompt智能改寫功能,預設開啟。開啟後,將使用大模型最佳化提示詞,對描述性不足、較為簡單的prompt提升效果較明顯。

完整參數列表請參考通義千問-影像編輯API

計費與限流

新加坡地區

模型名稱

計費單價

限流(主帳號與RAM子帳號共用)

免費額度(查看)

每秒請求數(RPS)限制

同時處理中任務數量

qwen-image-edit-plus

$0.03/張

2

同步介面無限制

100張

qwen-image-edit-plus-2025-10-30

$0.03/張

2

同步介面無限制

100張

qwen-image-edit

$0.045/張

2

同步介面無限制

100張

北京地區

模型名稱

計費單價

限流(主帳號與RAM子帳號共用)

免費額度(查看)

每秒請求數(RPS)限制

同時處理中任務數量

qwen-image-edit-plus

$0.028671/張

2

同步介面無限制

無免費額度

qwen-image-edit-plus-2025-10-30

$0.028671/張

2

同步介面無限制

qwen-image-edit

$0.043/張

2

同步介面無限制

計費說明:

  • 按成功產生的 映像張數 計費。模型調用失敗或處理錯誤不產生任何費用,也不消耗免費額度

  • 您可開啟“免費額度用完即停”功能,以避免免費額度耗盡後產生額外費用。詳情請參見免費額度

API參考

API的輸入輸出參數,請參見通義千問-影像編輯

錯誤碼

如果模型調用失敗並返回報錯資訊,請參見錯誤資訊進行解決。

常見問題

Q: qwen-image-edit 支援多輪對話式編輯嗎?

A: 不支援。qwen-image-edit模型本身的設計是單輪執行,即每次調用都是一個獨立的、無狀態的編輯任務,不會記憶之前的編輯歷史。若想實現連續編輯,需將上次編輯產生的圖片作為新的輸入圖片,再次調用服務。

Q: 如何查看模型調用量?

A: 模型的調用資訊存在小時級延遲,在模型調用完一小時後,請在模型觀測(新加坡北京頁面,查看調用量、調用次數、成功率等指標。如何查看模型調用記錄

更多問題請參見映像產生常見問題