-
imageformats-master.rar下载
资源介绍
C# 处理小众图片源码,是从源码库下载 imageformats,放在此是为了自己以后学习方便,希望你也能尽快处理好,我耽误了两天。欢迎留言交流!
public static string LoadPgmFile(string fileName)
{
try
{
var bmp = BitmapExtensions.Load(fileName);
if (bmp == null)
{
try { bmp = (Bitmap)Bitmap.FromFile(fileName); }
catch (Exception e) { Debug.WriteLine(e.Message); }
}
if (bmp == null)
throw new ApplicationException("Failed to convert pictures");
MemoryStream ms = new MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] arr = new byte[ms.Length];
ms.Position = 0;
ms.Read(arr, 0, (int)ms.Length);
ms.Close();
return Convert.ToBase64String(arr);
}
catch (Exception e)
{
return e.ToString();
}
}