Leadtools.Converters Namespace > RasterRenderBuffer Class : ToRasterImage Method |
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();
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.
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); }); }
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); } } } }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2