RasterImageRenderProperties Class
Syntax
public class RasterImageRenderProperties
Public Class RasterImageRenderProperties
public sealed class RasterImageRenderProperties
function Leadtools.Converters.RasterImageRenderProperties()
public ref class RasterImageRenderProperties
Example
The following example shows how to use RasterImageRenderProperties to render a RasterImage into the surface of a Windows Runtime WriteableBitmap using a few of the options specified.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;
using Leadtools.Converters;
public async void RasterImageRenderPropertiesExample()
{
RasterCodecs codecs = new RasterCodecs();
string srcFileName = @"Assets\Ocr1.tif";
string[] destFileNames =
{
@"Ocr1_Normal.png",
@"Ocr1_ScaleToGrary.png"
};
// Load the source image
RasterImage srcRasterImage;
StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
ILeadStream loadStream = LeadStreamFactory.Create(loadFile);
using (IDisposable leadStreamDisposable = loadStream as IDisposable)
{
srcRasterImage = await codecs.LoadAsync(loadStream);
}
// Create writeable bitmaps that fit inside 300 by 300 pixels keeping the image aspect ratio
LeadRect destRect = LeadRectHelper.Create(0, 0, 300, 300);
destRect = RasterImage.CalculatePaintModeRectangle(
srcRasterImage.ImageWidth,
srcRasterImage.ImageHeight,
destRect,
RasterPaintSizeMode.Fit,
RasterPaintAlignMode.Near,
RasterPaintAlignMode.Near);
// Create the writeable bitmaps
for (int i = 0; i < 2; i++)
{
WriteableBitmap bitmap = new WriteableBitmap(destRect.Width, destRect.Height);
// Create a RasterRenderBuffer object for the bitmap
RasterRenderBuffer renderBuffer = RasterRenderBuffer.CreateFromWriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight, bitmap.PixelBuffer);
// Render the image into the buffer using scale to gray and without
RasterImageRenderProperties properties = new RasterImageRenderProperties();
if (i == 0)
properties.RenderDisplayMode = RasterImageRenderDisplayModeFlags.None;
else
properties.RenderDisplayMode = RasterImageRenderDisplayModeFlags.ScaleToGray;
RasterImageRenderer.Render(srcRasterImage, renderBuffer, destRect, properties);
bitmap.Invalidate();
// Save the image using LEAD as PNG
using (RasterImage saveImage = RasterImageConverter.ConvertFromImageSource(bitmap, ConvertFromImageOptions.None))
{
StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileNames[i], CreationCollisionOption.ReplaceExisting);
ILeadStream saveStream = LeadStreamFactory.Create(saveFile);
using (IDisposable leadStreamDisposable = saveStream as IDisposable)
{
await codecs.SaveAsync(saveImage, saveStream, RasterImageFormat.Png, 32);
}
}
}
// Clean up
srcRasterImage.Dispose();
codecs.Dispose();
}