public void SetYUVData(
IntPtr buffer,
long bufferCount,
RasterYUVFormat yuvFormat
)
public:
void SetYUVData(
IntPtr buffer,
int64 bufferCount,
RasterYUVFormat yuvFormat
)
def SetYUVData(self,buffer,bufferCount,yuvFormat):
buffer
Buffer that contains the YUV data.
bufferCount
Size of the data buffer pointed to by buffer. If this value is incorrect, this method will throw an exception.
yuvFormat
Specifies the YUV data format.
This function is designed to be used mainly for use in mobile imaging to facilitate filling a BITMAPHANDLE structure using live frames from the mobile device's camera.
The function ignores the image's view perspective, so it must match the orientation of the YUV buffer. In most cases, the YUV buffer is top-to-bottom, so the ViewPerspective should be TopLeft. If the YUV buffer is flipped, the ViewPerspective should be BottomLeft, so it will be automatically flipped before saving or painting.
The YUV data should contain studio video YUV, with Y values ranging from 16 to 235 and U,V values ranging from 16 to 240. Values outside this range are clipped: values below 16 will be considered as if they were 16. Y values above 235 will be clipped to 235, U/V values above 240 will be clipped to 240.
The only supported bits per pixel are 8, 24 and 32.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Core;
using Leadtools.ImageProcessing.Color;
using Leadtools.Dicom;
using Leadtools.Drawing;
using Leadtools.Controls;
using Leadtools.Svg;
public void SetYUVDataExample()
{
string fileName = Path.Combine(LEAD_VARS.ImagesDir, "nv21.bin");
using (RasterCodecs codecs = new RasterCodecs())
{
using (RasterImage image = new RasterImage(RasterMemoryFlags.Conventional, 1920, 1080, 24, RasterByteOrder.Bgr, RasterViewPerspective.TopLeft, null, null, 0))
{
using (FileStream yuvFile = File.OpenRead(fileName))
{
int size = 1920 * 1080 * 3 / 2;
Byte[] yuvBuffer = new Byte[size];
yuvFile.Read(yuvBuffer, 0, size);
image.SetYUVData(yuvBuffer, 0, size, RasterYUVFormat.NV21);
codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "nv21_net.jpg"), RasterImageFormat.Jpeg, 0);
Byte[] yuvBuffer2 = new byte[size];
image.GetYUVData(RasterYUVFormat.YV12, yuvBuffer2, 0, yuvBuffer2.Length);
image.SetYUVData(yuvBuffer2, 0, yuvBuffer2.Length, RasterYUVFormat.YV12);
codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "nv21_net_2.jpg"), RasterImageFormat.Jpeg, 0);
System.Diagnostics.Debug.WriteLine("Save succeeded");
}
}
}
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";
}
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