Reputation: 1
How to create overlay in Fo-Dicom, need code example to create and show overlay layer using fo-dicom Created overlay using below code but Import dicom it does not show any over not sure what is mistake.
DicomFile dicomFile = DicomFile.Open(sourceDicomFileName, FileReadOption.ReadAll);
ushort width = dicomFile.Dataset.GetSingleValue<ushort>(DicomTag.Columns);
ushort height = dicomFile.Dataset.GetSingleValue<ushort>(DicomTag.Rows);
byte[] packedbitarray = Array.Empty<byte>();
Application.Current.Dispatcher.Invoke(() =>
{
var grid = new Grid { Width = width, Height = height };
var text = new TextBlock
{
Text = "OVERLAY",
FontSize = 32,
FontWeight = FontWeights.Bold,
HorizontalAlignment = HorizontalAlignment.Center
};
grid.Children.Add(text);
grid.Measure(new Size(grid.Width, grid.Height));
grid.Arrange(new Rect(new Size(grid.Width, grid.Height)));
var rtb = new RenderTargetBitmap(
(int)grid.Width,
(int)grid.Height,
96,
96,
PixelFormats.Pbgra32);
rtb.Render(grid);
int stride = rtb.PixelWidth * 4;
int size = rtb.PixelHeight * stride;
byte[] coloredPixels = new byte[size];
rtb.CopyPixels(coloredPixels, stride, 0);
BitArray bits = new BitArray(width * height);
for (int i = 0; i < size / 4; i++)
{
bits[i] = coloredPixels[4 * i + 3] == 0 ? false : true;
}
packedbitarray = new byte[Math.Max(1, bits.Length / 8)];
bits.CopyTo(packedbitarray, 0);
});
dicomFile.Dataset.Add(new DicomUnsignedShort(new DicomTag(0x6000, 0x0010), width));
dicomFile.Dataset.Add(new DicomUnsignedShort(new DicomTag(0x6000, 0x0011), height));
dicomFile.Dataset.Add(new DicomCodeString(new DicomTag(0x6000, 0x0040), "G"));
dicomFile.Dataset.Add(new DicomSignedShort(new DicomTag(0x6000, 0x0050), new short[] { 1, 1 }));
dicomFile.Dataset.Add(new DicomUnsignedShort(new DicomTag(0x6000, 0x0100), 1));
dicomFile.Dataset.Add(new DicomUnsignedShort(new DicomTag(0x6000, 0x0102), 0));
MemoryByteBuffer buffer = new MemoryByteBuffer(packedbitarray);
dicomFile.Dataset.Add(new DicomOtherByte(new DicomTag(0x6000, 0x3000), buffer));
dicomFile.Save(destDicomFileName);
Upvotes: 0
Views: 19