public static void Convert(
byte[] buffer,
int bufferOffset,
int width,
int inBitsPerPixel,
int outBitsPerPixel,
RasterByteOrder inOrder,
RasterByteOrder outOrder,
RasterColor[] inPalette,
RasterColor[] outPalette,
int alpha
)
public:
static void Convert(
array<byte>^ buffer,
int bufferOffset,
int width,
int inBitsPerPixel,
int outBitsPerPixel,
RasterByteOrder inOrder,
RasterByteOrder outOrder,
array<RasterColor>^ inPalette,
array<RasterColor>^ outPalette,
int alpha
)
def Convert(self,buffer,bufferOffset,width,inBitsPerPixel,outBitsPerPixel,inOrder,outOrder,] inPalette,] outPalette,alpha):
buffer
The input buffer.
bufferOffset
The zero-based offset into the buffer where conversion should start.
width
Width in pixels of the input image data.
inBitsPerPixel
BitsPerPixel of the input image data.
outBitsPerPixel
BitsPerPixel of the desired output image data.
inOrder
The input color order.
outOrder
The output color order.
inPalette
The palette or 8-bit LUT for the existing data, before conversion. If the input data is not palettized and not grayscale, use NULL.
outPalette
The palette for the converted data. If the data is converted to 16 or 24 bits per pixel color, use NULL for no palette.
alpha
The alpha value if the destination bits per pixel contains an alpha component
The conversion uses only one buffer, which must be large enough to hold the data before and after conversion.
Image data that is 8 bits per pixel or less must use a palette, and this method can use such data as input, output, or both. Therefore, you may need to specify the palette for the input, or for the output, or both.
If either inBitsPerPixel or outBitsPerPixel is 16, flags is used to determine whether the data should be treated as color or grayscale.
For more information, refer to Introduction to Image Processing With LEADTOOLS.
using Leadtools;
using Leadtools.Codecs;
public void RasterBufferConverterExample()
{
string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");
string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_16bits.bmp");
using (RasterCodecs codecs = new RasterCodecs())
{
codecs.ThrowExceptionsOnInvalidImages = true;
// Load the image, at 24 bit per pixel.
using (RasterImage srcImage = codecs.Load(srcFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1))
{
Assert.IsNotNull(srcImage);
Assert.IsTrue(srcImage.BitsPerPixel == 24);
// Create a new 16-bit image.
using (RasterImage destImage = new RasterImage(
RasterMemoryFlags.Conventional,
srcImage.Width,
srcImage.Height,
16,
srcImage.Order,
srcImage.ViewPerspective,
srcImage.GetPalette(),
IntPtr.Zero,
0))
{
Assert.IsNotNull(destImage);
Assert.IsTrue(destImage.BitsPerPixel == 16);
// Create a buffer large enough to hold a source or destination row
int bytesPerLine = Math.Max(srcImage.BytesPerLine, destImage.BytesPerLine);
byte[] buffer = new byte[bytesPerLine];
// Process each row from src to dest image
srcImage.Access();
destImage.Access();
for (int i = 0; i < srcImage.Height; i++)
{
srcImage.GetRow(i, buffer, 0, srcImage.BytesPerLine);
RasterBufferConverter.Convert(
buffer,
0,
srcImage.Width,
srcImage.BitsPerPixel,
destImage.BitsPerPixel,
srcImage.Order,
destImage.Order,
null,
null,
0);
destImage.SetRow(i, buffer, 0, destImage.BytesPerLine);
}
destImage.Release();
srcImage.Release();
// Save the destination image back to disk
codecs.Save(destImage, destFileName, RasterImageFormat.Bmp, 16);
}
}
}
}
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