This code demonstrates how it is possible to copy a whole ImageView content into another one. It shows in details how to copy image data, properties and metadata from a source to a destination image. It also gives the fast method, directly provided by IOLink, which gives the best performance.
using System;
using static System.Net.Mime.MediaTypeNames;
using System.IO;
using System.Reflection.Metadata;
{
public class CopyImageView
{
{
image.HasAlpha = false;
image.SpatialOrigin =
new Vector3d(1.0, 2.0, 3.0);
image.SpatialSpacing =
new Vector3d(0.1, 0.2, 0.3);
image.SpatialUnit = "mm";
image.Metadata = rootNode;
Byte[] buffer =
new byte[image.Type.ByteCount() * fullRegion.
ElementCount];
Array.Fill<Byte>(buffer, 0x42);
image.WriteRegion(fullRegion, buffer);
return image;
}
{
{
throw new ApplicationException("Source image does not have READ capability");
}
{
throw new ApplicationException(
"Destination image does not have WRITE and RESHAPE capability");
}
}
public static void Main(string[] args)
{
var imageSrc = CreateImageView();
CopyImageViewContent(imageSrc, imageDst);
Console.WriteLine(imageDst.ToString());
Console.WriteLine(imageDst.Properties.Clone().ToString());
Console.WriteLine(imageDst.Metadata.Clone().ToString());
Console.WriteLine(imageDst.ToString());
Console.WriteLine(imageDst.Properties.Clone().ToString());
Console.WriteLine(imageDst.Metadata.Clone().ToString());
}
}
}
Definition DataType.cs:24
uint ByteCount()
Definition DataType.cs:285
Definition ImageTypeId.cs:20
static ImageType IMAGE_SEQUENCE
Definition ImageTypeId.cs:122
Definition ImageViewFactory.cs:21
static ImageView Allocate(VectorXu64 shape, DataType type, ImageProperties properties, MetadataNode metadata)
Definition ImageViewFactory.cs:86
Definition ImageView.cs:31
ReadonlyMetadataNode Metadata
The MetadataNode associated with this ImageView instance.
Definition ImageView.cs:93
ReadonlyImageProperties Properties
The ImageProperties associated with this ImageView instance.
Definition ImageView.cs:85
VectorXu64 Shape
The ImageView shape, the size of each of its dimensions.
Definition ImageView.cs:72
DataType Type
The type of the image's elements.
Definition ImageView.cs:78
unsafe void ReadRegion(RegionXu64 region, byte[] dst)
Definition ImageView.cs:271
bool Support(ImageCapabilitySet flags)
Checks if the ImageView supports the given capabilities.
Definition ImageView.cs:178
unsafe void WriteRegion(RegionXu64 region, byte[] src)
Definition ImageView.cs:388
virtual void Reshape(VectorXu64 shape, DataType dataType)
Definition ImageView.cs:466
A Region using dynamic vectors.
Definition RegionXu64.cs:14
uint ElementCount
The number of elements in this region.
Definition RegionXu64.cs:139
static RegionXu64 CreateFullRegion(VectorXu64 regionSize)
Utility factory that create the region of origin [0, 0, 0] and given size.
Definition RegionXu64.cs:173
A factory to create VariantDataValue instances from a great variety of types.
Definition VariantDataValueFactory.cs:14
Definition Vector3d.cs:27
A dynamically sized arithmetic vector.
Definition VectorXu64.cs:14
Definition CreateDataFrame.cs:6
Definition AccessCapabilities.cs:11
ImageInterpretation
Interpretation of an Image.
Definition ImageInterpretation.cs:14
ImageCapability
Define capabilities of an ImageView.
Definition ImageCapability.cs:14
DataTypeId
A collection of built-in data types.
Definition DataTypeId.cs:14