←Select platform

Realize(BitmapSource) Method

Summary

Draws the container on the surface of the specified bitmap source.

Syntax

C#
VB
C++
public virtual BitmapSource Realize( 
   BitmapSource source 
) 
  
Public Overloads Overridable Function Realize( _ 
   ByVal source As BitmapSource _ 
) As BitmapSource 
public: 
virtual BitmapSource^ Realize(  
   BitmapSource^ source 
)  

Parameters

source
The System.Windows.Media.Imaging.BitmapSource object on which to draw this AnnContainer. Must not be null (Nothing in VB).

Return Value

A System.Windows.Media.Imaging.BitmapSource object that contains the combination of the original source in source overlayed with the annotation objects of this container. This is a new bitmap source with the same size as source.

Remarks

To create a System.Windows.Media.Imaging.BitmapSource representation of an AnnContainer, you must first create a System.Windows.Media.Imaging.BitmapSource object, fill it with the required background color and then call Realize.

Note that this method does not perform any scaling or offsetting. The container will be rendered at location 0,0 and with size equals to the container current size (ActualWidth and ActualHeight). Hence, typically, source will have the same size as the container. Otherwise, if the size of source is smaller than the container size, the returned bitmap source will be clipped. You can however use the bitmap source returned from this method as the source for a combine operation with another bitmap source to offset or scale the representation of the objects.

To render this container on the surface of a LEADTOOLS Leadtools.RasterImage, use Realize(rasterimage).

Example

This example will show how to render the container into a bitmap source and save it as PNG to disk.

C#
VB
using Leadtools; 
using Leadtools.Windows.Annotations; 
using Leadtools.Windows.Controls; 
using Leadtools.Codecs; 
//using Leadtools.Demos; 
//using Leadtools.Help; 
 
private void RealizeBitmapSourceExample(AnnContainer container) 
{ 
   int width = (int)container.ActualWidth; 
   int height = (int)container.ActualHeight; 
   int stride = (width * 32 + 7) / 8; 
   byte[] pixels = new byte[height * stride]; 
 
   // Create a bitmap source with the same size as the container, this is the background of the realize operation 
   BitmapSource backImage = BitmapSource.Create( 
      width, 
      height, 
      96.0, 
      96.0, 
      PixelFormats.Pbgra32, 
      null, 
      pixels, 
      stride); 
 
   // Render the container on the image 
   BitmapSource containerRender = container.Realize(backImage); 
 
   // Save it to disk 
   using (FileStream stream = File.Create(@"C:\Users\Public\Documents\LEADTOOLS Images\ContainerRender.png")) 
   { 
      PngBitmapEncoder encoder = new PngBitmapEncoder(); 
      encoder.Frames.Add(BitmapFrame.Create(containerRender)); 
      encoder.Save(stream); 
   } 
} 
Imports Leadtools.Windows.Annotations 
Imports Leadtools.Windows.Controls 
Imports Leadtools 
Imports Leadtools.Codecs 
 
Private Sub RealizeBitmapSourceExample(ByVal container As AnnContainer) 
   Dim width As Integer = CType(container.ActualWidth, Integer) 
   Dim height As Integer = CType(container.ActualHeight, Integer) 
   Dim stride As Integer = (width * 32 + 7) \ 8 
   Dim pixels(height * stride - 1) As Byte 
 
   ' Create a bitmap source with the same size as the container, this is the background of the realize operation 
   Dim backImage As BitmapSource = BitmapSource.Create( 
      width, 
      height, 
      96.0, 
      96.0, 
      PixelFormats.Pbgra32, 
      Nothing, 
      pixels, 
      stride) 
 
   ' Render the container on the image 
   Dim containerRender As BitmapSource = container.Realize(backImage) 
 
   ' Save it to disk 
   Using stream As FileStream = File.Create("C:\Users\Public\Documents\LEADTOOLS Images\ContainerRender.png") 
      Dim encoder As New PngBitmapEncoder() 
      encoder.Frames.Add(BitmapFrame.Create(containerRender)) 
      encoder.Save(stream) 
   End Using 
End Sub 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Windows.Annotations Assembly