Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

What does myImage refer to in this code?

Im trying to stream a image from one computer to another and i have found this code on stack overflow and i cant figure out what "myImage" in this code refers to. Is it a path to the image that im going to stream? I have tried making a variable called myImage as a string but i got ToStream highlighted in red saying "string doesnt contain a definition Tostream". so i guess it isnt the path.if someone could help me figure out what it means it would be very helpful. Thank you. The code is below

 

public static Stream ToStream(this Image image, ImageFormat format) {
  var stream = new System.IO.MemoryStream();
  image.Save(stream, format);
  stream.Position = 0;
  return stream;
}

var stream = myImage.ToStream(ImageFormat.Gif);

 

Link to post
Share on other sites

Someone correct me if I'm wrong, but it looks like you're trying to invoke ToStream in an object which you have declared called myImage, but myImage isn't declared as a Stream so doesn't get the method ToStream

Meh some build specs...

Meh some inspirational quote meh...

Link to post
Share on other sites
10 minutes ago, CheeseburgerChad said:

Someone correct me if I'm wrong, but it looks like you're trying to invoke ToStream in an object which you have declared called myImage, but myImage isn't declared as a Stream so doesn't get the method ToStream

so if i understood ur statement correctly what u mean is i havent declared myImage as a stream? so i did try declaring it as a stream now but i get the error saying stream doesnt contain a definition for ToStream. By the way this is where i found the code : https://stackoverflow.com/questions/1668469/system-drawing-image-to-stream-c-sharp

Link to post
Share on other sites

My mistake, I thought at first glance that you were dealing with Java, not C#. I'm a Java guy. Anyway its difficult to just copy code like that from SO, stuff doesn't like to work together without modification. Someone else with C# experience will have to pick up from here.

Meh some build specs...

Meh some inspirational quote meh...

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×