Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,204 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# Combining images | ||
|
||
## Merge multiple images | ||
|
||
#### C# | ||
```C# | ||
using (MagickImageCollection images = new MagickImageCollection()) | ||
{ | ||
// Add the first image | ||
MagickImage first = new MagickImage("Snakeware.png"); | ||
images.Add(first); | ||
|
||
// Add the second image | ||
MagickImage second = new MagickImage("Snakeware.png"); | ||
images.Add(second); | ||
|
||
// Create a mosaic from both images | ||
using(MagickImage result = images.Mosaic()) | ||
{ | ||
// Save the result | ||
result.Write("Mosaic.png"); | ||
} | ||
} | ||
``` | ||
|
||
#### VB.NET | ||
```VB.NET | ||
Using images As New MagickImageCollection() | ||
' Add the first image | ||
Dim first As New MagickImage("Snakeware.png") | ||
images.Add(first) | ||
|
||
' Add the second image | ||
Dim second As New MagickImage("Snakeware.png") | ||
images.Add(second) | ||
|
||
' Create a mosaic from both images | ||
Using result As MagickImage = images.Mosaic() | ||
' Save the result | ||
result.Write("Mosaic.png") | ||
End Using | ||
End Using | ||
``` | ||
|
||
## Create animated gif | ||
|
||
#### C# | ||
```C# | ||
using (MagickImageCollection collection = new MagickImageCollection()) | ||
{ | ||
// Add first image and set the animation delay to 100ms | ||
collection.Add("Snakeware.png"); | ||
collection[0].AnimationDelay = 100; | ||
|
||
// Add second image, set the animation delay to 100ms and flip the image | ||
collection.Add("Snakeware.png"); | ||
collection[1].AnimationDelay = 100; | ||
collection[1].Flip(); | ||
|
||
// Optionally reduce colors | ||
QuantizeSettings settings = new QuantizeSettings(); | ||
settings.Colors = 256; | ||
collection.Quantize(settings); | ||
|
||
// Optionally optimize the images (images should have the same size). | ||
collection.Optimize(); | ||
|
||
// Save gif | ||
collection.Write("Snakeware.Animated.gif"); | ||
} | ||
``` | ||
|
||
#### VB.NET | ||
```VB.NET | ||
Using collection As New MagickImageCollection() | ||
' Add first image and set the animation delay to 100ms | ||
collection.Add("Snakeware.png") | ||
collection(0).AnimationDelay = 100 | ||
|
||
' Add second image, set the animation delay to 100ms and flip the image | ||
collection.Add("Snakeware.png") | ||
collection(1).AnimationDelay = 100 | ||
collection(1).Flip() | ||
|
||
' Optionally reduce colors | ||
Dim settings As New QuantizeSettings() | ||
settings.Colors = 256 | ||
collection.Quantize(settings) | ||
|
||
' Optionally optimize the images (images should have the same size). | ||
collection.Optimize() | ||
|
||
' Save gif | ||
collection.Write("Snakeware.Animated.gif") | ||
End Using | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
# Convert image | ||
|
||
## Convert image from one format to another | ||
|
||
#### C# | ||
```C# | ||
// Read first frame of gif image | ||
using (MagickImage image = new MagickImage("Snakeware.gif")) | ||
{ | ||
// Save frame as jpg | ||
image.Write("Snakeware.jpg"); | ||
} | ||
|
||
// Write to stream | ||
MagickReadSettings settings = new MagickReadSettings(); | ||
// Tells the xc: reader the image to create should be 800x600 | ||
settings.Width = 800; | ||
settings.Height = 600; | ||
|
||
using (MemoryStream memStream = new MemoryStream()) | ||
{ | ||
// Create image that is completely purple and 800x600 | ||
using (MagickImage image = new MagickImage("xc:purple", settings)) | ||
{ | ||
// Sets the output format to png | ||
image.Format = MagickFormat.Png; | ||
// Write the image to the memorystream | ||
image.Write(memStream); | ||
} | ||
} | ||
|
||
// Read image from file | ||
using (MagickImage image = new MagickImage("Snakeware.png")) | ||
{ | ||
// Sets the output format to jpeg | ||
image.Format = MagickFormat.Jpeg; | ||
// Create byte array that contains a jpeg file | ||
byte[] data = image.ToByteArray(); | ||
} | ||
``` | ||
|
||
#### VB.NET | ||
```VB.NET | ||
' Read first frame of gif image | ||
Using image As New MagickImage("Snakeware.gif") | ||
' Save frame as jpg | ||
image.Write("Snakeware.jpg") | ||
End Using | ||
|
||
Dim settings As New MagickReadSettings() | ||
' Tells the xc: reader the image to create should be 800x600 | ||
settings.Width = 800 | ||
settings.Height = 600 | ||
|
||
Using memStream As New MemoryStream() | ||
' Create image that is completely purple and 800x600 | ||
Using image As New MagickImage("xc:purple", settings) | ||
' Sets the output format to png | ||
image.Format = MagickFormat.Png | ||
' Write the image to the memorystream | ||
image.Write(memStream) | ||
End Using | ||
End Using | ||
|
||
' Read image from file | ||
Using image As New MagickImage("Snakeware.png") | ||
' Sets the output format to jpeg | ||
image.Format = MagickFormat.Jpeg | ||
' Create byte array that contains a jpeg file | ||
Dim data As Byte() = image.ToByteArray() | ||
End Using | ||
``` | ||
|
||
## Convert CMYK to RGB | ||
|
||
#### C# | ||
```C# | ||
// Uses sRGB.icm, eps/pdf produce better result when you set this before loading. | ||
MagickReadSettings settings = new MagickReadSettings(); | ||
settings.ColorSpace = ColorSpace.sRGB; | ||
|
||
// Create empty image | ||
using (MagickImage image = new MagickImage()) | ||
{ | ||
// Reads the eps image, the specified settings tell Ghostscript to create an sRGB image | ||
image.Read("Snakeware.eps", settings); | ||
// Save image as tiff | ||
image.Write("Snakeware.tiff"); | ||
} | ||
|
||
// Read image from file | ||
using (MagickImage image = new MagickImage("Snakeware.jpg")) | ||
{ | ||
// Add a CMYK profile if your image does not contain a color profile. | ||
image.AddProfile(ColorProfile.USWebCoatedSWOP); | ||
|
||
// Adding the second profile will transform the colorspace from CMYK to RGB | ||
image.AddProfile(ColorProfile.SRGB); | ||
// Save image as png | ||
image.Write("Snakeware.png"); | ||
} | ||
|
||
// Use custom color profile | ||
using (MagickImage image = new MagickImage("Snakeware.jpg")) | ||
{ | ||
// First add a CMYK profile if your image does not contain a color profile. | ||
image.AddProfile(ColorProfile.USWebCoatedSWOP); | ||
|
||
// Adding the second profile will transform the colorspace from your custom icc profile | ||
image.AddProfile(new ColorProfile("YourProfile.icc")); | ||
// Save image as tiff | ||
image.Write("Snakeware.tiff"); | ||
} | ||
``` | ||
|
||
#### VB.NET | ||
```VB.NET | ||
' Uses sRGB.icm, eps/pdf produce better result when you set this before loading. | ||
Dim settings As New MagickReadSettings() | ||
settings.ColorSpace = ColorSpace.sRGB | ||
|
||
' Create empty image | ||
Using image As New MagickImage() | ||
' Reads the eps image, the specified settings tell Ghostscript to create an sRGB image | ||
image.Read("Snakeware.eps", settings) | ||
' Save image as tiff | ||
image.Write("Snakeware.tiff") | ||
End Using | ||
|
||
' Read image from file | ||
Using image As New MagickImage("Snakeware.jpg") | ||
' First add a CMYK profile if your image does not contain a color profile. | ||
image.AddProfile(ColorProfile.USWebCoatedSWOP) | ||
|
||
' Adding the second profile will transform the colorspace from CMYK to RGB | ||
image.AddProfile(ColorProfile.SRGB) | ||
' Save image as png | ||
image.Write("Snakeware.png") | ||
End Using | ||
|
||
' Read image from file | ||
Using image As New MagickImage("Snakeware.jpg") | ||
' First add a CMYK profile if your image does not contain a color profile. | ||
image.AddProfile(ColorProfile.USWebCoatedSWOP) | ||
|
||
' Adding the second profile will transform the colorspace from your custom icc profile | ||
image.AddProfile(New ColorProfile("YourProfile.icc")) | ||
' Save image as tiff | ||
image.Write("Snakeware.tiff") | ||
End Using | ||
``` |
Oops, something went wrong.