Hi Manu,
We have our application from where image is generated form HTML file and saved to Blob. We are using WebBrowser control for that. Below is the code for that.
public Stream CaptureWebPageScreen(string strhtml)
{
string tempno = DateTime.Now.TimeOfDay.TotalMilliseconds.ToString();
WebBrowser wb = new WebBrowser();
wb.AllowNavigation = true;
wb.ScrollBarsEnabled = false;
wb.Navigate(strhtml + "?" + tempno);
wb.Refresh(WebBrowserRefreshOption.Completely);
//wb.DocumentText = strhtml;
do
{
Application.DoEvents();
Thread.Sleep(5000);
}
while (wb.ReadyState != WebBrowserReadyState.Complete);
wb.Width = wb.Document.Body.ScrollRectangle.Width;
wb.Height = wb.Document.Body.ScrollRectangle.Height;
Bitmap bitmap = new Bitmap(wb.Width, wb.Height);
//wb.BringToFront();
wb.DrawToBitmap(bitmap, new System.Drawing.Rectangle(0, 0, wb.Width, wb.Height));
Graphics Grfx = Graphics.FromImage(bitmap);
Grfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
Grfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
Grfx.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
Grfx.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
Grfx.TextContrast = 0;
Grfx.DrawImage(bitmap, 0, 0, wb.Width, wb.Height);
wb.Dispose();
var imgstream = new MemoryStream();
bitmap.Save(imgstream, ImageFormat.Jpeg);
imgstream.Position = 0;
bitmap.Dispose();
Grfx.Dispose();
return imgstream;
}
Above method returns the Memory stream, which we are storing to Blob. Below is the code for the same.
public string UploadImage(Model.UploadFileInfo objfile, System.IO.Stream image, string imgcontainer = FileUploadBlobSetting.IMAGE_CONTAINER, bool IsFileshare = false)
{
var blobClient = account.CreateCloudBlobClient();
var blobRef = blobClient.GetBlockBlobReference(GetFileName(imgcontainer, objfile));
var temindex = objfile.Path.LastIndexOf('.') + 1;
blobRef.Properties.ContentType = "image/" + objfile.Path.Substring(temindex, objfile.Path.Length - temindex);
blobRef.UploadFromStream(image);
}
Can you please help me?