Click here to Skip to main content
15,566,615 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello so i'm trying to change convert a type which is :
C#
string img = Convert.ToString(System.Drawing.Image);

and its giving me : Error CS0119 'Image' is a type, which is not valid in the given context

i'm using a sdk and the code is :
FSDK.CImage image = new FSDK.CImage(imageHandle);
System.Drawing.Image frameImage = image.ToCLRImage();
pictureBox1.ImageUrl = frameImage;

What I have tried:

C#
string img = Convert.ToString(System.Drawing.Image);
Posted
Updated 20-Mar-22 17:20pm
v3

The error is quite clear - you're passing a type name to a method which expects an instance of an object.

Pass the actual object you want to convert instead - for example:
C#
System.Drawing.Image image = ...;
string img = Convert.ToString(img);

However, that almost certainly won't do what you want. It will return the result of calling the image's ToString method, which is only going to return the type name. But since you haven't explained precisely what you're trying to do, we can't tell you how to fix that.
 
Share this answer
 
Comments
Maciej Los 18-Mar-22 9:05am    
5ed!
You cannot convert a class to a string!
You can only convert an object, which is an instance of a class.
e.g.
C#
var myImage = Image.FromFile("SampleImage.jpg");
var myString = Convert.ToString(myImage)
What are you trying to achieve?
 
Share this answer
 
Comments
Natann 022 20-Mar-22 22:16pm    
to display a image
i'm using a sdk and the code is :
System.Drawing.Image frameImage = image.ToCLRImage();
pictureBox1.ImageUrl = frameImage;
If you want to store and load image data in a string you could use this code:

C#
private string SaveImage(Image image)
{
    using (MemoryStream m = new MemoryStream())
    {
        image.Save(m, image.RawFormat);

        byte[] imageBytes = m.ToArray();

        return Convert.ToBase64String(imageBytes);
    }
}

private Image LoadImage(string base64)
{
    byte[] bytes = Convert.FromBase64String(base64);

    Image image;

    using (MemoryStream ms = new MemoryStream(bytes))
    {
        image = Image.FromStream(ms);
    }

    return image;
}
 
Share this answer
 
Comments
Natann 022 20-Mar-22 22:31pm    
Thank you for your suggestion

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900