So, you think that transparency is impossible with 1 bit images? Well, you're right. But that doesn't mean that we can't fake it. A clever trick is to burn the annotation, with transparency, into an 8-bit greyscale image. Then convert that image to 1 bit. This will create the illusion that the annotation is transparent.
For this example I started off with an 8-bit greyscale image and drew a red rectangleAnnotation with alpha value of 100. The Code for this is simply,
this.annotateViewer1.Annotations.CreateAnnotation(new RectangleAnnotation(new Pen(Color.Red),new SolidBrush(Color.FromArgb(100, 255,0,0))));
Me.annotateViewer1.Annotations.CreateAnnotation(New RectangleAnnotation(New Pen(Color.Red),New SolidBrush(Color.FromArgb(100, 255,0,0))))
Next, I burned the annotation onto the greyscale image. Finally, I converted the Image to 1-bit.
- foreach(Layer l in this.annotateViewer1.Annotations.Layers)
- AtalaImage tmpImage = this.annotateViewer1.Image;
- this.annotateViewer1.Image = tmpImage.GetChangedPixelFormat(PixelFormat.Pixel1bppIndexed);
- For Each l As Layer In Me.annotateViewer1.Annotations.Layers
- Next l
- Dim tmpImage As AtalaImage = Me.annotateViewer1.Image
- Me.annotateViewer1.Image = tmpImage.GetChangedPixelFormat(PixelFormat.Pixel1bppIndexed)
There, thats it! The last image was left in such a large size so it can be seen that the conversion actually looks pretty good. This process can be used on any transparent Annotation.