Leadtools.Windows.Annotations Namespace > AnnContainer Class > Realize Method : Realize(BitmapSource) Method |
public virtual BitmapSource Realize( BitmapSource source )
'Declaration Public Overloads Overridable Function Realize( _ ByVal source As BitmapSource _ ) As BitmapSource
'Usage Dim instance As AnnContainer Dim source As BitmapSource Dim value As BitmapSource value = instance.Realize(source)
public: virtual BitmapSource^ Realize( BitmapSource^ source )
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).
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
using Leadtools; using Leadtools.Windows.Annotations; using Leadtools.Windows.Controls; using Leadtools.Codecs; 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); } }