Initializes the buffered compression engine.
public void StartCompress(int width,int height,int bitsPerPixel,Leadtools.RasterByteOrder order,Leadtools.RasterViewPerspective viewPerspective,int inputDataLength,byte[] outputData,int outputDataIndex,int outputDataLength,Leadtools.Codecs.CodecsCompression compression,Leadtools.Codecs.CodecsCompressDataCallback callback)
Public Overloads Sub StartCompress( _ByVal width As Integer, _ByVal height As Integer, _ByVal bitsPerPixel As Integer, _ByVal order As Leadtools.RasterByteOrder, _ByVal viewPerspective As Leadtools.RasterViewPerspective, _ByVal inputDataLength As Integer, _ByVal outputData() As Byte, _ByVal outputDataIndex As Integer, _ByVal outputDataLength As Integer, _ByVal compression As Leadtools.Codecs.CodecsCompression, _ByVal callback As Leadtools.Codecs.CodecsCompressDataCallback _)
public void StartCompress(int width,int height,int bitsPerPixel,Leadtools.RasterByteOrder order,Leadtools.RasterViewPerspective viewPerspective,int inputDataLength,byte[] outputData,int outputDataIndex,int outputDataLength,Leadtools.Codecs.CodecsCompression compression,Leadtools.Codecs.CodecsCompressDataCallback callback)
public void startCompress(int width,int height,int bitsPerPixel,RasterByteOrder order,RasterViewPerspective viewPerspective,int inputDataLength,byte[] outputData,int outputDataIndex,int outputDataLength,CodecsCompression compression,CodecsCompressDataListener callback)
function Leadtools.Codecs.RasterCodecs.StartCompress(Int32,Int32,Int32,RasterByteOrder,RasterViewPerspective,Int32,Byte[],Int32,Int32,CodecsCompression,CodecsCompressDataCallback)(width ,height ,bitsPerPixel ,order ,viewPerspective ,inputDataLength ,outputData ,outputDataIndex ,outputDataLength ,compression ,callback)
public:void StartCompress(int width,int height,int bitsPerPixel,Leadtools.RasterByteOrder order,Leadtools.RasterViewPerspective viewPerspective,int inputDataLength,array<byte>^ outputData,int outputDataIndex,int outputDataLength,Leadtools.Codecs.CodecsCompression compression,Leadtools.Codecs.CodecsCompressDataCallback^ callback)
width
The image being compressed width in pixels.
height
The image being compressed height in pixels.
bitsPerPixel
The image being compressed bits/pixel value.
order
The image being compressed byte order.
viewPerspective
The image being compressed view perspective value.
inputDataLength
Size in bytes of the input image data.
outputData
Array of bytes which will be filled with the compressed data.
outputDataIndex
Index into outputData where the compressed data should be inserted.
outputDataLength
Size of outputData in bytes.
compression
Type of compression to use. Valid values are:
| Value | Meaning |
|---|---|
| CodecsCompression.Cmp | LEAD CMP compression format |
| CodecsCompression.Jpeg444 | JPEG File Interchange Format using YUV 4:4:4 color spacing |
| CodecsCompression.Jpeg422 | JPEG File Interchange Format using YUV 4:2:2 color spacing |
| CodecsCompression.Jpeg411 | JPEG File Interchange Format using YUV 4:1:1 color spacing |
| CodecsCompression.TifJpeg444 | JPEG JTIF using YUV 4:4:4 color spacing |
| CodecsCompression.TifJpeg422 | JPEG JTIF using YUV 4:2:2 color spacing |
| CodecsCompression.TifJpeg411 | JPEG JTIF using YUV 4:1:1 color spacing |
| CodecsCompression.Lead0 | LEAD 1 bit, lossless compression |
| CodecsCompression.Lead1 | LEAD 1 bit, excellent compression |
| CodecsCompression.TiffCcitt | TIFF CCITT |
| CodecsCompression.TiffCcittG3Fax1Dim | CCITT Group 3 one dimensional |
| CodecsCompression.TiffCcittG3Fax2Dim | CCITT Group 3 two dimensional |
| CodecsCompression.TiffCcittG4Fax | CCITT Group 4 two dimensional |
callback
The callback method responsible for writing or handling the compressed data.
This method initializes the buffered compression engine. The compression is then carried out using the Compress method. It is ended by the StopCompress method.
If order is set to RasterByteOrder.Bgr and viewPerspective is RasterViewPerspective.TopLeft then the data that you put into the input buffer must be RasterByteOrder.Bgr and loaded from top left.
The compression process starts after the first call to Compress. The callback is called when the output buffer is filled with compressed data or after completing the compression process. callback is responsible for emptying the output buffer - storing it, sending it, or doing other processing.
The following is a flow chart that shows the relationship of these methods:
Call StopCompress to end the compression process started by a call to StartCompress.
The quality factor of the compressed data is obtained as follows:
This method does not support signed data images.
This example demonstrates low-level image compression using StartCompress, Compress and StopCompress. The callback method for writing the output is included at the end of the example
using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Color;using Leadtools.Svg;using LeadtoolsExamples.Common;public void CompressExample(){RasterCodecs codecs = new RasterCodecs();string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_CompressData.cmp");// Load the image to at 24-bits per pixelRasterImage image = codecs.Load(srcFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1);if (image.ViewPerspective != RasterViewPerspective.TopLeft)image.ChangeViewPerspective(RasterViewPerspective.TopLeft);// Create the output file_compressStream = File.Create(destFileName);// Calculate the bytes per line in the input buffer, without paddingint lineBytes = image.Width * 3;// Allocate a buffer for the incoming uncompressed data. Note that we// are compressing 16 lines at a time. You should always use multiples of 16byte[] inBuffer = new byte[16 * lineBytes];// Allocate an output buffer. This is where the compressed data will// go. Note that this allocates 1024-byte packets.byte[] outBuffer = new byte[1024];// Lock down the imageimage.Access();// Initialize the compression enginecodecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.QualityAndSize;codecs.StartCompress(image.Width,image.Height,image.BitsPerPixel,image.Order,image.ViewPerspective,16 * lineBytes,outBuffer,0,outBuffer.Length,CodecsCompression.Cmp,MyCodecsCompressDataCallback);// Compress the dataint i = 0;while (i < image.Height) // i is incremented at the end{// Compression of the 16-line chunk starts hereint j = 0;int inBufferIndex = 0;while ((i + j) < image.Height && j < 16){// Get one line at timeimage.GetRow(i + j, inBuffer, inBufferIndex, lineBytes);// Move to next lineinBufferIndex += lineBytes;j++;}// This is the main function that will do the actual Compressioncodecs.Compress(inBuffer, 0);i += 16;}// Reset the compression enginecodecs.StopCompress();// Release the image and close the fileimage.Release();_compressStream.Close();// Clean upcodecs.Dispose();}FileStream _compressStream;byte[] _compressBuffer;bool MyCodecsCompressDataCallback(int width, int height, int bitsPerPixel, RasterByteOrder order, RasterViewPerspective viewPerspective, RasterNativeBuffer buffer){// Write data to the fileif (_compressBuffer == null || _compressBuffer.Length < buffer.Length)_compressBuffer = new byte[(int)buffer.Length];Marshal.Copy(buffer.Data, _compressBuffer, 0, (int)buffer.Length);_compressStream.Write(_compressBuffer, 0, (int)buffer.Length);return true;}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.ColorImports Leadtools.DrawingImports Leadtools.SvgPublic Sub CompressExample()Dim codecs As RasterCodecs = New RasterCodecs()Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_CompressData.cmp")' Load the image to at 24-bits per pixelDim image As RasterImage = codecs.Load(srcFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1)If image.ViewPerspective <> RasterViewPerspective.TopLeft Thenimage.ChangeViewPerspective(RasterViewPerspective.TopLeft)End If' Create the output file_compressStream = File.Create(destFileName)' Calculate the bytes per line in the input buffer, without paddingDim lineBytes As Integer = image.Width * 3' Allocate a buffer for the incoming uncompressed data. Note that we' are compressing 16 lines at a time. You should always use multiples of 16Dim inBuffer As Byte() = New Byte(16 * lineBytes - 1) {}' Allocate an output buffer. This is where the compressed data will' go. Note that this allocates 1024-byte packets.Dim outBuffer As Byte() = New Byte(1023) {}' Lock down the imageimage.Access()' Initialize the compression enginecodecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.QualityAndSizecodecs.StartCompress(image.Width, image.Height, image.BitsPerPixel, image.Order, image.ViewPerspective, 16 * lineBytes, outBuffer, 0, outBuffer.Length, CodecsCompression.Cmp, AddressOf MyCodecsCompressDataCallback)' Compress the dataDim i As Integer = 0Do While i < image.Height ' i is incremented at the end' Compression of the 16-line chunk starts hereDim j As Integer = 0Dim inBufferIndex As Integer = 0Do While (i + j) < image.Height AndAlso j < 16' Get one line at timeimage.GetRow(i + j, inBuffer, inBufferIndex, lineBytes)' Move to next lineinBufferIndex += lineBytesj += 1Loop' This is the main function that will do the actual Compressioncodecs.Compress(inBuffer, 0)i += 16Loop' Reset the compression enginecodecs.StopCompress()' Release the image and close the fileimage.Release()_compressStream.Close()' Clean upcodecs.Dispose()End SubPrivate _compressStream As FileStreamPrivate _compressBuffer As Byte()Private Function MyCodecsCompressDataCallback(ByVal width As Integer, ByVal height As Integer, ByVal bitsPerPixel As Integer, ByVal order As RasterByteOrder, ByVal viewPerspective As RasterViewPerspective, ByVal buffer As _RasterNativeBuffer) As Boolean' Write data to the fileIf _compressBuffer Is Nothing OrElse _compressBuffer.Length < buffer.Length Then_compressBuffer = New Byte(CType(buffer.Length, Integer) - 1) {}End IfMarshal.Copy(buffer.Data, _compressBuffer, 0, CType(buffer.Length, Integer))_compressStream.Write(_compressBuffer, 0, CType(buffer.Length, Integer))Return TrueEnd FunctionPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class

Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.