Image are Download using Web Client and byte code pass for base64 conversion.
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Web;
using System.Web.UI;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void convert_Click(object sender, EventArgs e)
{
byte[] raw;
raw = new WebClient().DownloadData(txturl.Text);
Context.Response.Write(CreateBase64Image(raw));
}
private string CreateBase64Image(byte[] fileBytes)
{
System.Drawing.Image streamImage;
/*
Ensure we've streamed the document out correctly before we commit to the
conversion */
using (MemoryStream ms = new MemoryStream(fileBytes))
{
/*
Create a new image, saved as a scaled version of the original */
streamImage = (System.Drawing.Image.FromStream(ms));
}
using (MemoryStream ms = new MemoryStream())
{
/*
Convert this image back to a base64 string */
streamImage.Save(ms,
System.Drawing.Imaging.ImageFormat.Png);
return Convert.ToBase64String(ms.ToArray());
}
}
}
No comments:
Post a Comment