导航菜单

图像上色

图像上色功能专门用于为黑白图片添加颜色,让历史照片、素描作品或黑白图像焕发新的生机。AI会根据提示词描述和图片内容,智能地为不同区域添加合适的颜色。

功能描述

图像上色功能利用AI的深度理解能力,分析黑白图片中的内容、结构和纹理,然后根据用户的提示词描述,为不同区域智能添加颜色。这种功能特别适合恢复历史照片、为素描作品上色或重新诠释黑白艺术。

使用方法

imageedit({
  imageUrl: "http://wanx.alicdn.com/material/20250318/colorization_1.jpeg",
  prompt: "蓝色背景,黄色的叶子。",
  function: "colorization"
})
```text

## 参数说明

| 参数 | 类型 | 必需 | 描述 |
|------|------|------|------|
| `imageUrl` | string | ✅ | 需要上色的黑白图片URL |
| `prompt` | string | ✅ | 上色描述,说明要添加的颜色和风格 |
| `function` | string | ❌ | 固定为"colorization" |
| `n` | number | ❌ | 生成图片数量默认1 |
| `model` | string | ❌ | 使用的模型默认wanx2.1-imageedit |
| `dashScopeApiKey` | string | ❌ | DashScope API密钥 |

## 使用示例

### 历史照片上色
```typescript
// 为老照片上色
imageedit({
  imageUrl: "https://example.com/old_photo.jpg",
  prompt: "为这张老照片添加自然的颜色,保持历史感,人物服装为深蓝色,背景为温暖的棕色"
})

// 为黑白肖像上色
imageedit({
  imageUrl: "https://example.com/portrait.jpg",
  prompt: "为肖像添加自然的肤色,眼睛为深棕色,头发为黑色,服装为深红色"
})
```text

### 素描作品上色
```typescript
// 为素描上色
imageedit({
  imageUrl: "https://example.com/sketch.jpg",
  prompt: "为素描添加水彩风格的颜色,花朵为粉红色,叶子为绿色,背景为淡蓝色"
})

// 为线稿上色
imageedit({
  imageUrl: "https://example.com/lineart.jpg",
  prompt: "为线稿添加动漫风格的颜色,人物服装为蓝色,头发为金色,背景为粉色"
})
```text

### 风景照片上色
```typescript
// 为风景上色
imageedit({
  imageUrl: "https://example.com/landscape.jpg",
  prompt: "为风景添加自然的颜色,天空为蓝色,草地为绿色,花朵为红色和黄色"
})

// 为建筑上色
imageedit({
  imageUrl: "https://example.com/building.jpg",
  prompt: "为建筑添加古典风格的颜色,外墙为红砖色,屋顶为深灰色,门窗为棕色"
})
```text

### 静物上色
```typescript
// 为静物上色
imageedit({
  imageUrl: "https://example.com/still_life.jpg",
  prompt: "为静物添加写实风格的颜色,花瓶为白色陶瓷,花朵为红色玫瑰,桌面为深木色"
})

// 为食物上色
imageedit({
  imageUrl: "https://example.com/food.jpg",
  prompt: "为食物添加诱人的颜色,面包为金黄色,水果为鲜艳的红色和绿色"
})
```text

## 提示词技巧

### 颜色描述
- **具体颜色**明确指出要使用的颜色"红色"、"蓝色"、"绿色"
- **颜色组合**描述颜色的搭配"红色和黄色"、"蓝色和绿色"
- **颜色风格**描述颜色的风格"自然的"、"鲜艳的"、"柔和的"

### 区域描述
- **主要对象**描述主要对象的颜色"人物服装为蓝色"
- **背景颜色**描述背景的颜色"背景为温暖的棕色"
- **细节颜色**描述细节部分的颜色"眼睛为深棕色"

### 风格描述
- **写实风格**追求自然的颜色效果
- **艺术风格**追求艺术化的颜色表现
- **历史风格**保持历史照片的怀旧感
- **现代风格**使用现代的色彩搭配

### 提示词结构
```typescript
// 标准上色提示词结构
imageedit({
  imageUrl: "https://example.com/image.jpg",
  prompt: "为[主要对象]添加[颜色描述],[背景颜色描述],[风格描述]"
})

// 示例
imageedit({
  imageUrl: "https://example.com/portrait.jpg",
  prompt: "为人物添加自然的颜色,服装为深蓝色,背景为温暖的棕色,保持写实风格"
})
```text