🔒 Locked
[.net] Array Problem
Advertisement
Original Post
Ok I may just be being a bit thick today, but this is my problem. I am storing webcam image capture data into an object, I am then assigning this object to an object array. The problem is that each field in the array has a pointer to the object and not the object itself. This means that when I come to convert the objects to images, the images are all the same and are of the last image captured. How do I store all the objects by value rather than reference?
This all depends on white kind of object you are trying to store - is it a Bitmap/Image type? If so, then the solution is to 'clone' the object.
VB.NET -
MyArray(i) = bmpimage.Clone()
C# -
MyArray = bmpimage.Clone();
Hope that helps.
VB.NET -
MyArray(i) = bmpimage.Clone()
C# -
MyArray = bmpimage.Clone();
Hope that helps.
Ah, well in that case your array should be of type 'Image' and you should store this value:
dataobjectinstance.GetImage()
If that doesn't work, try storing
dataobjectinstance.GetImage().Clone()
in your array.
By the way, I'm interested what library you're using to capture the webcam image if you don't mind telling?
dataobjectinstance.GetImage()
If that doesn't work, try storing
dataobjectinstance.GetImage().Clone()
in your array.
By the way, I'm interested what library you're using to capture the webcam image if you don't mind telling?
I found the sample code for the webcam capture here :- http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=1339&lngWId=10
Is dataobjectinstance.GetImage() .net2.0 code? (as the 1.1 code only seems to have getdata())
Is there a way of passing a reference object by value?
Is dataobjectinstance.GetImage() .net2.0 code? (as the 1.1 code only seems to have getdata())
Is there a way of passing a reference object by value?
Hmmm, yeh it's 2.0 code. Well try storing this:
dataobjectinstance.GetData(GetType(Image))
Or if that doesn't work:
DirectCast(a.GetData(GetType(Image)), Image)
Should all work nicely :)
Thanks for the link btw...
dataobjectinstance.GetData(GetType(Image))
Or if that doesn't work:
DirectCast(a.GetData(GetType(Image)), Image)
Should all work nicely :)
Thanks for the link btw...
I was trying to avoid the conversion to an image to try and speed the program up but I will use the getdata method until I port this across to 2.0
(I can't believe the difficulty I had in finding some sample code to demonstrate capturing images from a webcam. I thought it would be easy... how wrong I was!!)
Thanks for the help.
(I can't believe the difficulty I had in finding some sample code to demonstrate capturing images from a webcam. I thought it would be easy... how wrong I was!!)
Thanks for the help.
Ah, i see... I assume it works now though?
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement