Leadtools.Converters assembly

ToRasterImage Method

Show in webframe
Example 







Converts the data inside this buffer into a Leadtools.RasterImage.
Syntax
public RasterImage ToRasterImage()
'Declaration
 
Public Function ToRasterImage() As RasterImage
'Usage
 
Dim instance As RasterRenderBuffer
Dim value As RasterImage
 
value = instance.ToRasterImage()
public RasterImage ToRasterImage()

            

            
 function Leadtools.Converters.RasterRenderBuffer.ToRasterImage()
public:
RasterImage^ ToRasterImage(); 

Return Value

The Leadtools.RasterImage object created.
Remarks

The Leadtools.RasterImage returned will have the same width, height, color order and bits per pixel specified in Width, Height, Order and BitsPerPixel.

The image data are copied into the Leadtools.RasterImage.

You can use this method to quickly convert a Windows Runtime WriteableBitmap or HTML ImageData to a LEADTOOLS Leadtools.RasterImage object.

Example
Copy Code  
RasterImageRendererExamples.prototype.RasterImageRendererExample = function () {

   // Assume myCanvas is a Canvas on the page that has an image

   // 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;

   // Create a RasterRenderBuffer from the image data
   var destRect = Leadtools.LeadRectHelper.create(0, 0, width, height);
   var renderBuffer = Leadtools.Converters.RasterRenderBuffer.createFromHtmlImageData(imageData.width, imageData.height, pixelData);

   // Create a RasterImage from it
   var rasterImage = renderBuffer.toRasterImage();

   // Save it
   var createFileAsync = Windows.ApplicationModel.Package.current.installedLocation.createFileAsync("Assets\\RasterImage.png", Windows.Storage.CreationCollisionOption.replaceExisting).then(
      function (createFileAsyncResult) {
         var codecs = new Leadtools.Codecs.RasterCodecs();
         var leadStream = Leadtools.LeadStreamFactory.create(createFileAsyncResult);
         codecs.saveAsync(rasterImage, leadStream, Leadtools.RasterImageFormat.Png, 32);
      });
}
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);
         }
      }
   }
}
Requirements

Target Platforms

See Also

Reference

RasterRenderBuffer Class
RasterRenderBuffer Members

 

 


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