Jump to content
  • Advertisement
Sign in to follow this  
coolblue

[.net] Array Problem

This topic is 4674 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!