コード例 #1
0
        public string IconToBase64(Icon icon)
        {
            string str = string.Empty;
            string result;

            if (icon == null)
            {
                result = str;
            }
            else
            {
                Bitmap bitmap             = null;
                System.IO.MemoryStream ms = null;
                try
                {
                    ms     = new System.IO.MemoryStream();
                    bitmap = icon.ToBitmap();
                    bitmap.Save(ms, ImageFormat.Png);
                    byte[] array = new byte[ms.Length];
                    ms.Position = 0L;
                    ms.Read(array, 0, (int)ms.Length);
                    str = System.Convert.ToBase64String(array);
                }
                finally
                {
                    if (ms != null)
                    {
                        ms.Dispose();
                    }
                    if (bitmap != null)
                    {
                        bitmap.Dispose();
                    }
                }
                result = str;
            }
            return(result);
        }
コード例 #2
0
 public string IconToBase64(Icon icon)
 {
     string str = string.Empty;
     string result;
     if (icon == null)
     {
         result = str;
     }
     else
     {
         Bitmap bitmap = null;
         System.IO.MemoryStream ms = null;
         try
         {
             ms = new System.IO.MemoryStream();
             bitmap = icon.ToBitmap();
             bitmap.Save(ms, ImageFormat.Png);
             byte[] array = new byte[ms.Length];
             ms.Position = 0L;
             ms.Read(array, 0, (int)ms.Length);
             str = System.Convert.ToBase64String(array);
         }
         finally
         {
             if (ms != null)
             {
                 ms.Dispose();
             }
             if (bitmap != null)
             {
                 bitmap.Dispose();
             }
         }
         result = str;
     }
     return result;
 }