Skip to main content
gamedev.net
🔒 Locked

[.net] Array Problem

Started by coolblue 7 replies 1.1k views
Original Post
coolblue
coolblue
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?
alex_myrpg
alex_myrpg
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.
coolblue
coolblue
I am storing a System.Windows.Forms.DataObject
alex_myrpg
alex_myrpg
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?
coolblue
coolblue
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?
alex_myrpg
alex_myrpg
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...
coolblue
coolblue
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.
coolblue
coolblue
It does work now thanks.

I will just have to not display the pictures realtime to speed up the capture a bit.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.