Leadtools.Converters assembly

RasterImageRenderer Class

Show in webframe
Example 







Members 
Renders a LEADTOOLS Leadtools.RasterImage into the surface of Windows Runtime WriteableBitmap or HTML Canvas objects.
Object Model
Syntax
public static class RasterImageRenderer 
'Declaration
 
Public MustInherit NotInheritable Class RasterImageRenderer 
'Usage
 
Dim instance As RasterImageRenderer
public sealed static class RasterImageRenderer 

            

            
function Leadtools.Converters.RasterImageRenderer()
public ref class RasterImageRenderer abstract sealed 
Remarks

The RasterImageRenderer class provides support for rendering a LEADTOOLS Leadtools.RasterImage into a generic buffer containing 32-bit image data. This buffer can be the surface of a Windows Runtime WriteableBitmap object or the image data of HTML Canvas. The source Leadtools.RasterImage can have any bits/pixel or color order supported by LEADTOOLS.

To render any portion of a raster image into a Windows Runtime WriteableBitmap:

To render any portion of a raster image into a HTML Canvas:

You can also use an instance of RasterImageRenderProperties and change any of its properties to control the speed and quality of the render operation. Such as performing scale to gray or resample rendering.

RasterRenderBuffer also contains the RasterRenderBuffer.ToRasterImage helper method that allows you to convert the data inside a RasterRenderBuffer into a Leadtools.RasterImage object. This can be used to create a Leadtools.RasterImage from a Windows Runtime WriteableBitmap or HTML Canvas.

Example
Copy Code  
RasterImageRendererExamples.prototype.RasterImageRendererExample = function () {
   // Assume myCanvas is a Canvas on the page

   // Load the image
   var getFileAsync = Windows.ApplicationModel.Package.current.installedLocation.getFileAsync("Assets\\Ocr1.tif").then(
      function (getFileAsyncResult) {
         var codecs = new Leadtools.Codecs.RasterCodecs();
         var leadStream = Leadtools.LeadStreamFactory.create(getFileAsyncResult);
         codecs.loadAsync(leadStream).then(
            function (rasterImage) {

               // Get the canvas
               var myCanvas = document.getElementById("myCanvas");
               var context = myCanvas.getContext("2d");

               // Get the ImageData
               var imageData = context.createImageData(myCanvas.width, myCanvas.height);
               var pixelData = imageData.data;

               var width = imageData.width;
               var height = imageData.height;

               // Render the image into the canvas using Scale 2 Gray
               var destRect = Leadtools.LeadRectHelper.create(0, 0, width, height);
               var properties = new Leadtools.Converters.RasterImageRenderProperties();
               properties.renderDisplayMode = Leadtools.Converters.RasterImageRenderDisplayModeFlags.scaleToGray;
               var renderBuffer = Leadtools.Converters.RasterRenderBuffer.createFromHtmlImageData(imageData.width, imageData.height, pixelData);
               Leadtools.Converters.RasterImageRenderer.render(rasterImage, renderBuffer, srcRect, destRect, properties);

               // Set the image data back into the context
               context.putImageData(imageData, 0, 0);
            });
      });
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;
using Leadtools.Converters;

public async void RasterImageRendererExample()
{
   RasterCodecs codecs = new RasterCodecs();
   string srcFileName = @"Assets\Ocr1.tif";
   string destFileName = @"Ocr1_ScaleToGray.png";

   // Load the image
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   ILeadStream leadStream = LeadStreamFactory.Create(loadFile);
   RasterImage image = await codecs.LoadAsync(leadStream);

   // Create a writeable bitmap that fit inside 300 by 300 pixels keeping the image aspect ratio
   LeadRect destRect = LeadRectHelper.Create(0, 0, 300, 300);
   destRect = RasterImage.CalculatePaintModeRectangle(
      image.ImageWidth,
      image.ImageHeight,
      destRect,
      RasterPaintSizeMode.Fit,
      RasterPaintAlignMode.Near,
      RasterPaintAlignMode.Near);

   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
   RasterImageRenderProperties properties = new RasterImageRenderProperties();
   properties.RenderDisplayMode = RasterImageRenderDisplayModeFlags.ScaleToGray;
   RasterImageRenderer.Render(image, renderBuffer, destRect, properties);
   bitmap.Invalidate();

   // No need for the image anymore
   image.Dispose();

   // Save the writeable bitmap using PngEncoder
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName, CreationCollisionOption.ReplaceExisting);
   IRandomAccessStream stream = await saveFile.OpenAsync(FileAccessMode.ReadWrite);
   BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);
   Stream pixelStream = bitmap.PixelBuffer.AsStream();
   byte[] pixels = new byte[pixelStream.Length];
   await pixelStream.ReadAsync(pixels, 0, pixels.Length);
   encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, (uint)bitmap.PixelWidth, (uint)bitmap.PixelHeight, 96.0, 96.0, pixels);
   await encoder.FlushAsync();

   // Clean up
   codecs.Dispose();
}
Requirements

Target Platforms

See Also

Reference

RasterImageRenderer Members
Leadtools.Converters Namespace

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.