Saving Image with overlays as .bmp

Hello,
I am new here but an old CVB user, regards to everyone!
I would like to copy (or save) my display image including its current overlays as .bmp
Is there a way to do that?
Thank you very much!
Bartley

Hi Bartley,

I had a short look into the CommonVisionBlox.com (%cvb%doc) and searched for ‘destructive’.
Reason is, I remember, that there was something like you are looking for hidden somewhere in CVB.
And yes, there seem to be destructive overlays (destructive as they manipulate the pixel values of your .bmp) but not for the latest CVB++ and CVB.Net wrappers.

Maybe you can provide us some more insight in what you are trying to do so we might eventually find a way to achieve this.
Also, your preferred programming language might be helpful.

Cheers
Chris

1 Like

Hello Chris,
Thanks for your answer.
We are using C# and CVB.NET.
My client needs something simple: Every time we find a flaw in an image, we put an overlay label on that flaw. We need to be able to save that image with its overlay labels. This means that the client can have a folder on their computers with those images to be opened on Windows without running our program to see them. I suggest saving them as .bmp because I know CVB “likes” .bmp!
Looks simple but I can not be able to achieve it at the moment!
Thank you very much.

I remember having done something similar 5 years ago or so :stuck_out_tongue:
I will check the code tomorrow when I am back at the office but if I remember correctly I just saved the position and extents of the overlays and printed the images together with more data on a .pdf file.
The lib used for this had overlays that could be put on any element on the .pdf.

Still, Im not dead sure about this and will check if thats actually how it worked or if I printed the overlays on the image bevorehand.

In any case: What will always work would be to get linear access on the CVBImages and manipulate the pixel values of the pixels under the overlays. This means a bit of typing but should not be that much of a problem.
Here is a snippet on how to work with LinearAccess:

var path = Environment.ExpandEnvironmentVariables("%CVB%Tutorial/Clara.bmp"); 
var img = Image.FromFile(path); 
var width = img.Width; 
var height = img.Height; 
var linearAccess = img.Planes[0].GetLinearAccess(); 
var xInc = (int)(linearAccess.XInc); 
var yInc = (int)(linearAccess.YInc); 
IntPtr basePtr = linearAccess.BasePtr;  

unsafe 
{ 
  for (int y = 0; y < height; y++) 
  { 
    var line = (byte*)basePtr.ToPointer() + y * yInc; 
    for (int x = 0; x < width; x++) 
    { 
      var pixel = line + x * xInc; 
      *pixel = (*pixel + 20 > 255) ? (byte)255 : (byte)(*pixel + 20); 
    } 
  } 
}

However this might become unhandy as soon as you want to print text as well.
Maybe you could give me an update if thats the case.
Meanwhile I will keep searching what else I can find.

1 Like

Hi @BartleySharp and @Chris

allow me to weigh in… :wink:

@BartleySharp: It is unclear what UI base you are using - I am guessing either Forms or WPF. Regardless of UI technology: It is not possible to save display plus overlays (overlays in this context meaning the kind of object that can be added to the Stemmer.Cvb.Forms.Controls.Display.Overlays collection, i. e. basically almost all the objects that are in the Stemmer.Cvb.Forms.Overlays namespace or a Stemmer.Cvb.Wpf.Controls.Display object plus anything you might have added to the display canvas’ : Items collection) by means available from within CVB. That is basically a job for the underlying UI toolkit.

If I interpreted correctly what you want to achive, the following links might help, though:

What @Chris homed in to are destructive overlays - i. e. something you paint into the image and then save it by simply saving the images. This approach has its advantages and disadvantages:

  • Pro:
    • Fairly simple to achieve
    • You will always get the CVB image’s native resolution (if you use the above screenshot-like techniques you will always get the CVB image as it is being displayed - which is usually not exactly the native resolution as provided by the camera
  • Con:
    • Extra effort needed to transfer what is on your display into the image
    • Limited to the color depth of the camera image (but of course you could first convert e.g. mono to RGB and then paint destructive overlays in color)

If you decide to head down this alley, then you can draw whatever you want using the VPAT approach that @Chris described - or you could have a look at the Stemmer.Cvb.ImageDrawer class which provids a few easy-to-use basic shapes. For adding text, the Foundation package has a tool called “TextOut” but this has not yet been mapped to CVB.Net, so using this in a CVB.Net application is bound to be a bit hacky…

3 Likes

Good morning Chris and Illusive,
Thank you very much for your help.
I will try both solutions!
My very best regards