Tuesday 29 March 2011

GDI+ error in C# giving me headache

I already spend almost the 3 hours to solve this error for converting the image to string in C#. At last, I already find the solution. I need to store the image from the picture box to image object before converting to string and save it to local first to prevent this GDI+ error. This is my code:





Image imgMAD = pictureBox1.Image;

 Bitmap bp = new Bitmap(imgMAD);
 bp.Save("Image.jpg");


String strImg = Util.ConvertImageToString("Image.jpg");


bp.Dispose();
              





This is the function to convert image to string:


 public static string ConvertImageToString(string s_ImgPath)
{
            Image img = Image.FromFile(s_ImgPath);
            return Base64ImageToString(img, System.Drawing.Imaging.ImageFormat.Jpeg);
 }

No comments:

Post a Comment