Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

Save CWIMAQViewer image & overlay in VB

Hi, I want to save both the image and the overlay from
CWIMAQViewer object to an image in VB.
I used VB SavePicture function and it works, but the
result is not a bmp but still viewerable.
However, this causes memoryleaks.

Does anybody know a proper way of saving CWIMAQViewer image & overlays ?

Thanks
0 Kudos
Message 1 of 20
(13,372 Views)
visionpro -

If you have a non-destructive overlay on the image that you wish to keep, you must save the image with CWIMAQVision.WriteImageAndVisionInfo. This will save both the image and the vision info associated with it - in this case, the overlay.

Let me know if you have further questions regarding this. Thanks!

Greg Stoll
IMAQ R & D
National Instruments
Greg Stoll
LabVIEW R&D
0 Kudos
Message 2 of 20
(13,371 Views)

hi,

i dono whether this is the correct forum for this question..if its not,could someone please direct me to the correct one?

here's my problem:

im trying to not use the CWIMAQViewer at all in my application(im using VB.NET).is it possible for me to directly save the image from Grab into a variable?i have gone thru the examples provided,but i dont understand the connection between the Viewer and the variable that i declare for the image acquired using Grab..i dont see any code that actually saves the image from Grab into the variable.even if i omit the  IMAQViewer.Attach() code,the program is working fine.so,is there a way to do it?the reason i dont want to use the Viewer is because i dont need the image to be displayed or anything.i just need to do some color matching and return the color of a region in the image.

thank you..

0 Kudos
Message 3 of 20
(13,056 Views)
Hi rebecs,

The following code will create a new 32 bit RGB image named MyImage:

Dim MyImage As CWIMAQControls.CWIMAQImage
MyImage = CWIMAQVision1.CreateCWIMAQImage
MyImage.Type = CWIMAQControls.CWIMAQImageTypes.cwimaqImageTypeRGB32

Regards,
Luke H
0 Kudos
Message 4 of 20
(13,041 Views)
hi Luke,
 
thank you so much..i was getting kinda desperate Smiley Wink..i'll try it out and see.
thanks again!!
0 Kudos
Message 5 of 20
(13,034 Views)
hi,
i have used the code given and didnt have to use the viewer.
now i have run into another error..
i grouped all my grab codes into a function called grab(),coz i need to call it a few times throughout the program.
after calling the grab() function, i attempt to use the image(myImage) and perform color matching.however,i get this error:
 
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information:
The image is not large enough for the operation.

 

at:

CWIMAQVision1.LearnColor(myImage, ColInfo, ViewRect)

wer myImage is the image from grab(), ColInfo is the color info, and ViewRect is the region.when i debug,i can see that there is no image height and width.so i suspect that the image is not passed to the LearnColor correctly.but myImage is a global variable,so i dont understand y the function cant access it..i've even tried pasting all the grab codes before LearnColor,but still getting the same error..Smiley Sad

very grateful if someone can help..need to finish this by today..

thank u so much!!

 

 


0 Kudos
Message 6 of 20
(13,027 Views)
hi,
 i have pin pointed where the problem lies.
 
there seems to be a delay in storing the image in the myImage variable..i found this by inserting some textboxes that display the image height in certain locations.
i noticed that before and after the grab() function,the height is still 0,which means the image is not in the variable yet.
but just before i use it in the learn function(which is right after the grab),it gives me 600.so my guess is the image is taking a few seconds to be stored after the grab..Smiley Surprised
 
and another thing,the program worked perfectly with all those text boxes popping out..but when i remove them,i get the same error again..i guess thats because by waiting for me to click on the OK,there is some delay,so it evens out..without that,the program reaches the learn color too fast,without giving time for the image to be stored properly..Smiley Sad
 
if i put the grab codes in the load event of the form,evrything works fine..so i guess thats one way to solve it..but if someone can help me to do it without it,that would be great..
this is because i want the grab to be initiated by the user,instead of automatically doing it when the form loads..
 
thanks..
 
 
 
 
0 Kudos
Message 7 of 20
(13,010 Views)
rebecs,

There may be some delay due to the image being moved around in memory.  I'm not sure exactly what it's doing underneath.  Where is your project at?

Regards,
Luke H
0 Kudos
Message 8 of 20
(12,960 Views)

hi luke,

im sorry,but i dont understand wat u mean by  " Where is your project at?"..did u mean the direactory where i save my project?

i save it in: P:\MyDocuments\Visual Studio Projects\vision4..and sorry if this is not wat u wanted..

anyway,wat im trying to do is use this application as a dll and call it from a console based application.the delay still exists,coz when i debug,i can see that the image doesnt exist in the variable just before i use it for my LearnColor.Smiley Sad

since placing the image acqusition codes in the form load event solved the problem in my earlier app,i placed them in the constructor for the library.and guess wat..it worked!!Smiley Very Happy

i also used a timer that fires every 250ms.in the timer fired event,i placed the grabCW2 codes..and i also put a 1 second delay just before the LearnColor function.

but if there is a way to place all codes in one main function,i would be very happy..coz,as i said earlier,i want all actions to be initiated by the user..if only i could solve the delay in saving the image,then im done...

thank you so much for your help..Smiley Happy

0 Kudos
Message 9 of 20
(12,949 Views)


in the timer fired event,i placed the grabCW2 codes..

oops..its supposed to be Grab2CWSmiley Wink

0 Kudos
Message 10 of 20
(12,949 Views)