''' <summary>
''' Saves image as CMYK JPEG image.
''' </summary>
''' <param name="sourceImage">The source image.</param>
''' <param name="iccProfile">The ICC profile.</param>
''' <param name="outFilePath">The output file path.</param>
Public Sub SaveCmykJpegImage(sourceImage As Vintasoft.Imaging.VintasoftImage, iccProfile As Vintasoft.Imaging.ColorManagement.Icc.IccProfile, outFilePath As String)
If iccProfile Is Nothing Then
Throw New System.ArgumentNullException()
End If
If iccProfile.DeviceColorSpace <> Vintasoft.Imaging.ColorSpaceType.CMYK Then
Throw New System.InvalidOperationException()
End If
' convert image to BGR24 format
Dim converter As New Vintasoft.Imaging.ImageProcessing.ChangePixelFormatToBgrCommand(Vintasoft.Imaging.PixelFormat.Bgr24)
Using image As Vintasoft.Imaging.VintasoftImage = converter.Execute(sourceImage)
' create new color management decoding settings
Dim colorManagement As New Vintasoft.Imaging.ColorManagement.ColorManagementDecodeSettings()
' set output CMYK profile
colorManagement.OutputCmykProfile = iccProfile
' get color transform (BGR to CMYK)
Dim colorTransform As Vintasoft.Imaging.ColorManagement.ColorTransform = colorManagement.GetColorTransform(Vintasoft.Imaging.ColorSpaceFormats.Bgr, Vintasoft.Imaging.ColorSpaceFormats.Cmyk)
' create a color transform command
Dim command As New Vintasoft.Imaging.ImageProcessing.Color.ColorTransformCommand()
' set color transform
command.ColorTransform = colorTransform
' set format of channels of result image (4 channels to 8 bits)
command.OutputChannelsFormat = New Vintasoft.Imaging.BitmapChannelsFormat(4, 8)
command.ExecuteInPlace(image)
' create JPEG encoder
Dim encoder As New Vintasoft.Imaging.Codecs.Encoders.JpegEncoder()
' create settings of JPEG encoder
Dim settings As New Vintasoft.Imaging.Codecs.Encoders.JpegEncoderSettings()
' disable subsampling
settings.IsSubsamplingDisabled = True
Dim table As Integer() = New Integer() {8, 6, 6, 7, 6, 5, _
8, 7, 7, 7, 9, 9, _
8, 10, 12, 20, 13, 12, _
11, 11, 12, 25, 18, 19, _
15, 20, 29, 26, 31, 30, _
29, 26, 28, 28, 32, 36, _
46, 39, 32, 34, 44, 35, _
28, 28, 40, 55, 41, 44, _
48, 49, 52, 52, 52, 31, _
39, 57, 61, 56, 50, 60, _
46, 51, 52, 50}
' set quantization table of channels
settings.QuantizationTables = New Integer()() {table, table, table, table}
encoder.Settings = settings
' save image as CMYK JPEG image
image.Save(outFilePath, encoder)
End Using
End Sub