-
-
Notifications
You must be signed in to change notification settings - Fork 451
Expand file tree
/
Copy pathConvertImage.cs
More file actions
82 lines (60 loc) · 2.77 KB
/
Copy pathConvertImage.cs
File metadata and controls
82 lines (60 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.
using System.IO;
using ImageMagick;
namespace Magick.NET.Samples;
public static class ConvertImageSamples
{
public static void ConvertImageFromOneFormatToAnother()
{
// Read first frame of gif image
using var image = new MagickImage(SampleFiles.SnakewareGif);
// Save frame as jpg
image.Write(SampleFiles.OutputDirectory + "Snakeware.jpg");
var settings = new MagickReadSettings();
// Tells the xc: reader the image to create should be 800x600
settings.Width = 800;
settings.Height = 600;
using var memStream = new MemoryStream();
// Create image that is completely purple and 800x600
using var purple = new MagickImage("xc:purple", settings);
// Sets the output format to png
purple.Format = MagickFormat.Png;
// Write the image to the memorystream
purple.Write(memStream);
// Read image from file
using var snakeware = new MagickImage(SampleFiles.SnakewarePng);
// Sets the output format to jpeg
snakeware.Format = MagickFormat.Jpeg;
// Create byte array that contains a jpeg file
var data = snakeware.ToByteArray();
}
public static void ConvertCmykToRgb()
{
// Uses sRGB.icm, eps/pdf produce better result when you set this before loading.
var settings = new MagickReadSettings
{
ColorSpace = ColorSpace.sRGB
};
// Create empty image
using var eps = new MagickImage();
// Reads the eps image, the specified settings tell Ghostscript to create an sRGB image
eps.Read(SampleFiles.SnakewareEps, settings);
// Save image as tiff
eps.Write(SampleFiles.OutputDirectory + "Snakeware.tiff");
// Read image from file
using var png = new MagickImage(SampleFiles.SnakewareJpg);
// Will use the CMYK profile if the image does not contain a color profile.
// The second profile will transform the colorspace from CMYK to RGB
png.TransformColorSpace(ColorProfiles.USWebCoatedSWOP, ColorProfiles.SRGB);
// Save image as png
png.Write(SampleFiles.OutputDirectory + "Snakeware.png");
// Read image from file
using var tiff = new MagickImage(SampleFiles.SnakewareJpg);
// Will use the CMYK profile if your image does not contain a color profile.
// The second profile will transform the colorspace from your custom icc profile
tiff.TransformColorSpace(ColorProfiles.USWebCoatedSWOP, new ColorProfile(SampleFiles.YourProfileIcc));
// Save image as tiff
tiff.Write(SampleFiles.OutputDirectory + "Snakeware.tiff");
}
}