1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| [WebMethod]
public byte[] GenerateImageInBytes(string fName)
{
byte[] imageBytes = null;
FileInfo fInfo = new FileInfo(fName);
if (fInfo.Exists)
{
// File size
long fSize = fInfo.Length;
Bitmap img = new Bitmap(fName, false);
using (MemoryStream ms = new MemoryStream((int)fSize))
{
using (img)
{
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
}
imageBytes = ms.ToArray();
}
}
return imageBytes;
}
[WebMethod]
public string GenerateImageInBase64String(string fName)
{
byte[] imageBytes = this.GenerateImageInBytes(fName);
if (imageBytes != null)
{
return Convert.ToBase64String(imageBytes);
}
return null;
} |