Click here to Skip to main content
15,878,748 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have tried to convert but i cant...

What I have tried:

Stream stream = new MemoryStream();
                        myImage.Save(stream, ImageFormat.Bmp);
                        result = stream;
Updated 16-Jan-18 22:56pm
F-ES Sitecore 17-Jan-18 4:51am    
There is nothing wrong with the code you posted, the problem is in the greater context you're trying to get the working in and the large bits of information you are not supplying, such as what is "stream"? What is "result"? What is the ultimate aim of this code?

Your code saves an image to a stream in bitmap format.

To convert a stream containing a supported image type to a bitmap, use the Image.FromStream Method (System.Drawing)[^]:
using (Image image = Image.FromStream(stream))
    // Upon success image contains the bitmap
    //  and can be saved to a file:
Share this answer
The solution given is in VB.Please use C# equivalent.

Bitmap to Memory Stream and Vice Versa[^]
Share this answer

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