I think you need to look at learning some basics:
1) To "send my image to above function" you call the method with your image as a parameter:
byte[] data = ConvertImagetoByteArray(myImage);
2) That method does not return a stream: it uses a stream to convert the image to an array of bytes. It then returns the byte array.
3) Without knowing what you are doing with the socket, and what the exception is, we cannot tell what your error is. Most likely, it is a timeout, but without the relevant code fragment and error, that is just guessing...
"i got this Error: cannot convert from 'string' to 'System.Drawing.Image'
my code is:"
string[] images = Directory.GetFiles(subDirectory);
for (int k = 0; k < images.Length; k++)
{
string imagename = Path.GetFileName(images[k]);
Image image = (Image)imagename ;
Byte[] imageByteArray = ConvertImagetoByteArray(image );
}
"iam doing like this but i am getting above mentioned error"
There a couple of things here:
1) Casting a string to an Image does not load a file.
2) If you are handling file names, you do not need to load the image as an Image at all.
Either replace the cast:
Image image = (Image) imagename;
with an Image load:
Image image = Image.FromFile(imagename);
Or do not load it as an image at all; load it directly as bytes:
string[] images = Directory.GetFiles(subDirectory);
foreach (string filename in images)
{
byte[] imageByteArray = File.ReadAllBytes(filename);
}