openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.1.0-beta.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

examples/Images/Example02_SimpleImageEdit.cs

31lines · modeblame

8cc6643fJose Arriaga Maldonado2 years ago1using NUnit.Framework;
2using OpenAI.Images;
3using System;
4using System.IO;
5
6namespace OpenAI.Examples;
7
8public partial class ImageExamples
9{
10[Test]
11public void Example02_SimpleImageEdit()
12{
13ImageClient client = new("dall-e-2", Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
14
15string imageFilePath = Path.Combine("Assets", "images_flower_vase.png");
16string prompt = "A vase full of beautiful flowers.";
db6328acJose Arriaga Maldonado2 years ago17string maskFilePath = Path.Combine("Assets", "images_flower_vase_with_mask.png");
8cc6643fJose Arriaga Maldonado2 years ago18
19ImageEditOptions options = new()
20{
21Size = GeneratedImageSize.W512xH512,
22ResponseFormat = GeneratedImageFormat.Bytes
23};
24
25GeneratedImage edit = client.GenerateImageEdit(imageFilePath, prompt, maskFilePath, options);
26BinaryData bytes = edit.ImageBytes;
27
28using FileStream stream = File.OpenWrite($"{Guid.NewGuid()}.png");
29bytes.ToStream().CopyTo(stream);
30}
31}