-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
53 lines (43 loc) · 2.04 KB
/
Copy pathProgram.cs
File metadata and controls
53 lines (43 loc) · 2.04 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
using System.IO;
using ImageGear.Evaluation;
using ImageGear.Core;
using ImageGear.Formats;
using System;
using ImageGear.Formats.JPG;
using System.Xml.Linq;
namespace CompressUsingOptions
{
class Program
{
static void Main()
{
// Initialize common formats.
ImGearCommonFormats.Initialize();
// Specify options for saving.
ImGearSaveOptions saveJPGOptions = new ImGearSaveOptions();
// Set conversion mode.
saveJPGOptions.ConversionMode = ImGearRasterConversionModes.ANY;
// Set target color space.
saveJPGOptions.ForceColorspace = ImGearColorSpaceIDs.NONE;
// Create local control parameters for the filter corresponding to the format to be compressed (i.e. the global filter is not modified).
saveJPGOptions.Filters = new ImGearFileFilters();
// Get control parameters for the target format.
ImGearFormatParameters formatParameters = saveJPGOptions.Filters.Get(ImGearFormats.JPG).Parameters;
// Set output type for JPG format.
formatParameters.GetByName("SaveType").Value = (int)(ImGearJpegSaveType.Lossy);
// Set quality for Lossy compression ([1, 100]).
formatParameters.GetByName("Quality").Value = 30;
// Load PNG image file.
ImGearPage imGearPage = null;
using (FileStream inputStream = new FileStream(@"../../../../../../Sample Input/single-page.png", FileMode.Open, FileAccess.Read, FileShare.Read))
{
imGearPage = ImGearFileFormats.LoadPage(inputStream);
// Save to JPG file with options.
using (FileStream outputStream = new FileStream(@"../../../../../../Sample Output/single-page-out.jpg", FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
ImGearFileFormats.SavePage(imGearPage, outputStream, 0, ImGearSavingModes.OVERWRITE, ImGearSavingFormats.JPG, saveJPGOptions);
}
}
}
}
}