ToRasterImage Method
Summary
Converts the data inside this buffer into a RasterImage.
Syntax
function Leadtools.Converters.RasterRenderBuffer.ToRasterImage()
Return Value
The RasterImage object created.
Example
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;
using Leadtools.Converters;
public async void RasterRenderBufferToRasterImageExample()
{
string srcFileName = @"Assets\Ocr1.tif";
string destFileName = @"ToRasterImage.png";
// Load the source image
StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
IRandomAccessStream loadStream = await loadFile.OpenReadAsync();
WriteableBitmap bitmap = new WriteableBitmap(1, 1);
bitmap.SetSource(loadStream);
// Create a RasterRenderBuffer object for the bitmap
RasterRenderBuffer renderBuffer = RasterRenderBuffer.CreateFromWriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight, bitmap.PixelBuffer);
// Create a raster image from it and save it
using (RasterImage rasterImage = renderBuffer.ToRasterImage())
{
StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName, CreationCollisionOption.ReplaceExisting);
ILeadStream saveStream = LeadStreamFactory.Create(saveFile);
using (IDisposable leadStreamDisposable = saveStream as IDisposable)
{
using (RasterCodecs codecs = new RasterCodecs())
{
await codecs.SaveAsync(rasterImage, saveStream, RasterImageFormat.Png, 32);
}
}
}
}