Gets or sets the YUV conversion properties.
public ConversionYuvParameters YuvParameters { get; set; } Public Property YuvParameters As ConversionYuvParameters
public:property ConversionYuvParameters YuvParameters {ConversionYuvParameters get();void set ( ConversionYuvParameters );}
A ConversionYuvParameters structure that contains the CIELab conversion properties.
The YUV conversion properties. If this property value is null(Nothing), default values are assumed.
This example will convert a buffer from Yuv to Rgb Color Space.
using Leadtools;using Leadtools.Codecs;using Leadtools.ColorConversion;public byte[] GetYuvBufferFromImage(RasterImage bgrImage){// StartUp the ColorConversion.RasterColorConverterEngine.Startup();// Image buffer arraybyte[] bgrBuffer = new byte[bgrImage.Width * bgrImage.Height * 3];bgrImage.Access();// get image bufferfor (int i = 0; i < bgrImage.Height; i++)bgrImage.GetRow(i, bgrBuffer, (i * bgrImage.Width * 3), bgrImage.Width * 3);bgrImage.Release();// Initialize a new Converter objectRasterColorConverterEngine converter = new RasterColorConverterEngine();byte[] yuvBuffer = new byte[bgrBuffer.Length];try{// Start the color conversionconverter.Start(ConversionColorFormat.Bgr, ConversionColorFormat.Yuv, null);// convert the image bufferconverter.Convert(bgrBuffer, // input buffer0, // offset from the beginning of the source bufferyuvBuffer, // output buffer0, // offset from the beginning of the destination bufferbgrImage.Width, // pixels widthbgrImage.Height, // pixels height0, // 0 bytes align0); // 0 bytes align// stop the conversionconverter.Stop();}catch (Exception ex){MessageBox.Show(ex.Message);}RasterColorConverterEngine.Shutdown();return yuvBuffer;}public RasterImage GetImageFromYuvBuffer(byte[] yuvBuffer, int width, int height){// StartUp the ColorConversion.RasterColorConverterEngine.Startup();// Initialize a new Converter objectRasterColorConverterEngine converter = new RasterColorConverterEngine();// Initialize an image to hold the converted buffer.RasterImage yuvImage = null;try{yuvImage = new RasterImage(RasterMemoryFlags.Conventional, width, height, 24, RasterByteOrder.Bgr, RasterViewPerspective.TopLeft, null, IntPtr.Zero, 0);// Start the color conversionconverter.Start(ConversionColorFormat.Yuv, ConversionColorFormat.Bgr, null);// convert the image bufferconverter.ConvertToImage(yuvBuffer, // converted buffer0, // offset from the beginning of the source bufferyuvImage, // image to be savewidth, // pixels widthheight, // pixels height0, // 0 bytes align0); // 0 bytes align// stop the conversionconverter.Stop();}catch (Exception ex){MessageBox.Show(ex.Message);}// Shutdown the ColorConversion.RasterColorConverterEngine.Shutdown();return yuvImage;}public void YuvParametersPropertyExample(){// Startup the RasterCodecsRasterCodecs codecs = new RasterCodecs();// StartUp the ColorConversion.RasterColorConverterEngine.Startup();// The input file namestring inputFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");// load the input image as Bgr.RasterImage bgrImage = codecs.Load(inputFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1);int width = bgrImage.Width;int height = bgrImage.Height;byte[] yuvBuffer = GetYuvBufferFromImage(bgrImage);// Initialize the Rgb buffer arraybyte[] rgbBuffer = new byte[yuvBuffer.Length];//Byte ordering of the format; for Y41P:// U0 Y0 V0 Y1 U4 Y2 V4 Y3 Y4 Y5 Y6 Y7// 0 1 2 3 4 5 6 7 8 9 10 11// Put the Y component order first, then the U and V last as follows:// Y positions: 1,3,5,7,8,9,10,11// U positions: 0,4// V positions: 2,6int[] offset = { 1, 3, 5, 7, 8, 9, 10, 11, 0, 4, 2, 6 };// Initialize a new ConversionParameters class object.ConversionParameters convParams = new ConversionParameters();// Initialize the YuvParameters class property.ConversionYuvParameters yuvParameters = ConversionYuvParameters.Empty;// Determine the horizontal sub-sampling of UyuvParameters.UH = 4;// Determine the vertical sub-sampling of UyuvParameters.UV = 1;// Determine the horizontal sub-sampling of VyuvParameters.VH = 4;// Determine the vertical sub-sampling of VyuvParameters.VV = 1;//Set the byte orderingyuvParameters.Offsets = offset;//The YUV values rangeyuvParameters.Range = ConversionYuvRange.UseFull;// This represents the macro pixels(smallest group of pixels allowed),// which indicates how many actual pixels are in the macro pixel.// This value is important only in non - planar formatyuvParameters.MacroPixel = 8;//This is a Boolean value that represents the type of the YUV format (Planar = true, or non - Planar = false.)yuvParameters.Planar = false;// set the yuv parametersconvParams.YuvParameters = yuvParameters;// Determine the type of conversion to be used in the conversion, for YUVGeneric, only use UseBuiltInconvParams.Method = ConversionMethodFlags.UseBuiltIn;//Determine the type of conversion to be activated. For YUVGeneric, only UseBuiltInconvParams.ActiveMethod = ConversionMethodFlags.UseBuiltIn;// Initialize a new Converter objectRasterColorConverterEngine converter = new RasterColorConverterEngine();try{//Initialize the conversionconverter.Start(ConversionColorFormat.Yuv, ConversionColorFormat.Rgb, convParams);// Convert the Buffer from Yuv to Rgbconverter.Convert(yuvBuffer, 0, rgbBuffer, 0, width, height, 0, 0);// Change the Yuv ParametersconvParams.Method = ConversionMethodFlags.ChangeYuv;// Change the MacroPixel valueyuvParameters.Mask = ConversionYuvMaskFlags.MacroPixel;// Reset the MacroPixel Property.yuvParameters.MacroPixel = 16;convParams.YuvParameters = yuvParameters;// Convert the Buffer from Yuv to Rgbconverter.Convert(yuvBuffer, 0, rgbBuffer, 0, width, height, 0, 0);// Stop the conversionconverter.Stop();}catch (Exception ex){MessageBox.Show(ex.Message);rgbBuffer = null;}// the output File Name.string outputFileName = Path.Combine(LEAD_VARS.ImagesDir, "ResultImage.bmp");// Save the converted ImageRasterImage yuvImage = GetImageFromYuvBuffer(yuvBuffer, width, height);codecs.Save(yuvImage, outputFileName, RasterImageFormat.Bmp, 24);// Shutdown the ColorConversion.RasterColorConverterEngine.Shutdown();// Shutdown the RasterCodecs}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ColorConversionPublic Function GetYuvBufferFromImage(ByVal bgrImage As RasterImage) As Byte()' StartUp the ColorConversion.RasterColorConverterEngine.Startup()' Image buffer arrayDim bgrBuffer(bgrImage.Width * bgrImage.Height * 3) As Byte' get image bufferDim i As IntegerbgrImage.Access()For i = 0 To bgrImage.HeightbgrImage.GetRow(i, bgrBuffer, (i * bgrImage.Width * 3), bgrImage.Width * 3)Next ibgrImage.Release()' Initialize a new Converter objectDim converter As New RasterColorConverterEngine()Dim yuvBuffer(bgrBuffer.Length) As ByteTry' Start the color conversionconverter.Start(ConversionColorFormat.Bgr, ConversionColorFormat.Yuv, Nothing)' convert the image bufferconverter.Convert(bgrBuffer,0,yuvBuffer,0,bgrImage.Width,bgrImage.Height,0,0)' stop the conversionconverter.Stop()Catch ex As ExceptionMessageBox.Show(ex.Message)End TryRasterColorConverterEngine.Shutdown()Return yuvBufferEnd FunctionPublic Function GetImageFromYuvBuffer(ByVal yuvBuffer As Byte(), ByVal width As Integer, ByVal height As Integer) As RasterImage' StartUp the ColorConversion.RasterColorConverterEngine.Startup()' Initialize a new Converter objectDim Converter As New RasterColorConverterEngine()' Initialize an image to hold the converted buffer.Dim yuvImage As RasterImage = NothingTryyuvImage = New RasterImage(RasterMemoryFlags.Conventional, width, height, 24, RasterByteOrder.Bgr, RasterViewPerspective.TopLeft, Nothing, IntPtr.Zero, 0)' Start the color conversionConverter.Start(ConversionColorFormat.Yuv, ConversionColorFormat.Bgr, Nothing)' convert the image bufferConverter.ConvertToImage(yuvBuffer,0,yuvImage,width,height,0,0)' stop the conversionConverter.Stop()Catch ex As ExceptionMessageBox.Show(ex.Message)End Try' Shutdown the ColorConversion.RasterColorConverterEngine.Shutdown()Return yuvImageEnd FunctionPublic Sub YuvParametersExampleExample()' Startup the RasterCodecsDim codecs As New RasterCodecs()' StartUp the ColorConversion.RasterColorConverterEngine.Startup()' The input file nameDim inputFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")' load the input image as Bgr.Dim bgrImage As RasterImage = codecs.Load(inputFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1)Dim width As Integer = bgrImage.WidthDim height As Integer = bgrImage.HeightDim yuvBuffer() As Byte = GetYuvBufferFromImage(bgrImage)' Initialize the Rgb buffer arrayDim rgbBuffer(yuvBuffer.Length) As Byte' Byte ordering of the format; for Y41P:' U0 Y0 V0 Y1 U4 Y2 V4 Y3 Y4 Y5 Y6 Y7' 0 1 2 3 4 5 6 7 8 9 10 11' Put the Y component order first, then the U and V last as follows:' Y positions: 1,3,5,7,8,9,10,11' U positions: 0,4' V positions: 2,6Dim offset() As Integer = {1, 3, 5, 7, 8, 9, 10, 11, 0, 4, 2, 6}' Initialize a new ConversionParameters class object.Dim convParams As ConversionParameters = New ConversionParameters' Initialize the YuvParameters class property.Dim yuvParameters As ConversionYuvParameters = ConversionYuvParameters.Empty' Determine the horizontal sub-sampling of UyuvParameters.UH = 4' Determine the vertical sub-sampling of UyuvParameters.UV = 1' Determine the horizontal sub-sampling of VyuvParameters.VH = 4' Determine the vertical sub-sampling of VyuvParameters.VV = 1' Set the byte orderingyuvParameters.Offsets = offset' The YUV values rangeyuvParameters.Range = ConversionYuvRange.UseFull' This represents the macro pixels(smallest group of pixels allowed),' which indicates how many actual pixels are in the macro pixel.' This value is important only in non - planar formatyuvParameters.MacroPixel = 8' This is a Boolean value that represents the type of the YUV format (Planar = true, or non - Planar = false.)yuvParameters.Planar = FalseconvParams.YuvParameters = yuvParameters' Determine the type of conversion to be used in the conversion, for YUVGeneric, only use UseBuiltInconvParams.Method = ConversionMethodFlags.UseBuiltIn' Determine the type of conversion to be activated. For YUVGeneric, only UseBuiltInconvParams.ActiveMethod = ConversionMethodFlags.UseBuiltIn' Initialize a new Converter objectDim converter As New RasterColorConverterEngineTry' Initialize the conversionconverter.Start(ConversionColorFormat.Yuv, ConversionColorFormat.Rgb, convParams)' Convert the Buffer from Yuv to Rgbconverter.Convert(yuvBuffer, 0, rgbBuffer, 0, width, height, 0, 0)' Change the Yuv ParametersconvParams.Method = ConversionMethodFlags.ChangeYuv' Change the MacroPixel valueyuvParameters.Mask = ConversionYuvMaskFlags.MacroPixel' Reset the MacroPixel Property.yuvParameters.MacroPixel = 16convParams.YuvParameters = yuvParameters' Convert the Buffer from Yuv to Rgbconverter.Convert(yuvBuffer, 0, rgbBuffer, 0, width, height, 0, 0)' Stop the conversionconverter.Stop()Catch ex As ExceptionMessageBox.Show(ex.Message)rgbBuffer = NothingEnd Try' the output File Name.Dim outputFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "ResultImage.bmp")' Save the converted ImageDim yuvImage As RasterImage = GetImageFromYuvBuffer(yuvBuffer, width, height)codecs.Save(yuvImage, outputFileName, RasterImageFormat.Bmp, 24)' Shutdown the ColorConversion.RasterColorConverterEngine.Shutdown()' Shutdown the RasterCodecsEnd SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
