public override void AnnotationRenderWebPage(Guid renderTaskId, string renderUrl, AnnotationRenderWebPageComplete annotationRenderWebPageComplete) { ThreadPool.QueueUserWorkItem(delegate(object s) { string imageMimeType = ""; int imageWidth = 0; int imageHeight = 0; _renderWebPage = null; try { if (renderUrl.ToLower().EndsWith(".jpg") || renderUrl.ToLower().EndsWith(".jpeg")) { Obany.Communications.CommunicationsResult communicationResult = Obany.Communications.CommunicationsManager.Get(new Uri(renderUrl), null); if (communicationResult.Status == OperationStatus.Success) { using (System.IO.MemoryStream ms = new System.IO.MemoryStream(communicationResult.BinaryResponse)) { using (System.Drawing.Image image = System.Drawing.Bitmap.FromStream(ms)) { imageMimeType = "image/jpeg"; imageWidth = image.Width; imageHeight = image.Height; _renderWebPage = communicationResult.BinaryResponse; } } } } } catch { } if (_renderWebPage == null) { Obany.Render.Web.HtmlToImage h2i = new Obany.Render.Web.HtmlToImage(); _renderWebPage = h2i.RenderToBitmap(renderUrl, out imageWidth, out imageHeight, out imageMimeType); } if (annotationRenderWebPageComplete != null) { annotationRenderWebPageComplete(_renderWebPage != null, renderTaskId, _renderWebPage, imageWidth, imageHeight, imageMimeType, null); } }); }
/// <summary> /// Generate a thumbnail for the url /// </summary> /// <param name="url">The url to generate the thumbnail for</param> /// <param name="width">The width of the thumbnail</param> /// <param name="height">The height of the thumbnail</param> /// <param name="isPreview">Is this a request for a preview</param> /// <returns>The location of the generated thumbnail</returns> public string GenerateThumbnail(string url, int width, int height, bool isPreview) { string returl = ""; if (System.IO.Directory.Exists(_thumbnailCacheFolder)) { string filename = System.IO.Path.Combine(_thumbnailCacheFolder, Obany.Cryptography.MD5.HashHex(url) + ".jpg"); if (System.IO.File.Exists(filename)) { returl = filename; } else { if (!isPreview) { try { _htmlToImage = new Obany.Render.Web.HtmlToImage(); string imageMimeType; int imageWidth = 0; int imageHeight = 0; byte[] data = _htmlToImage.RenderToBitmap(url, out imageWidth, out imageHeight, out imageMimeType); if (data != null) { using (System.IO.MemoryStream ms = new System.IO.MemoryStream(data)) { using (System.Drawing.Image image = new System.Drawing.Bitmap(ms)) { using (System.Drawing.Image thumbImage = ResizImage(image, width, height)) { if (thumbImage != null) { ImageCodecInfo codecInfo = GetEncoderInfo(ImageFormat.Jpeg); Encoder encoder = Encoder.Quality; EncoderParameter encoderParam = new EncoderParameter(encoder, 75L); EncoderParameters encoderParams = new EncoderParameters(1); encoderParams.Param[0] = encoderParam; thumbImage.Save(filename, ImageFormat.Jpeg); if (ThumbnailAdded != null) { ThumbnailAdded(new System.IO.FileInfo(filename).Length); } returl = filename; } } } } } _htmlToImage = null; } catch { } } } } return(returl); }