'''' This code is part of Document Solutions for Imaging demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsGrapeCity.Documents.ImagingImportsGrapeCity.Documents.Html '' This sample shows how to render a web page specified by a URL'' to an image (here we render the Google home page) using DsHtml.'''' DsHtml natively supports only two image formats - JPEG and PNG.'' For these formats, we directly use the GcHtmlRenderer class'' to render the page to a temporary image file, which is then'' copied to the output stream.'''' Other image formats (BMP, GIF, TIFF) require rendering HTML'' to a temporary GcBitmap, and saving that to the target format.'''' Please see notes in comments at the top of HelloWorldHtml'' sample code for details on adding DsHtml to your projects.PublicClassRenderPage0FunctionGenerateImageStream(ByVal targetMime AsString,ByVal pixelSize AsSize,ByVal dpi AsSingle,ByVal opaque AsBoolean,Optional sampleParams AsString() = Nothing) AsStream '' The Uri of the web page to render:Dim uri = New Uri("http://www.google.com") '' Depending on the target format, we may need a temp file:Dim tfile AsString = Nothing '' The stream to contain the return image:Dim ms = NewMemoryStream() '' Create an instance of GcHtmlBrowser that is used to render HTML,'' and an HtmlPage instance rendering the source Uri:Using browser = Util.NewHtmlBrowser(), htmlPage = browser.NewPage(uri, NewPageOptions() With {.WindowSize = pixelSize})'' JPEG, PNG and WebP are natively supported by DsHtml. Other image formats can be'' supported by rendering to a GcBitmap and saving it to the target format:SelectCase targetMimeCase MimeTypes.JPEG tfile = Path.GetTempFileName() htmlPage.SaveAsJpeg(tfile, NewJpegOptions())Case MimeTypes.PNG tfile = Path.GetTempFileName() htmlPage.SaveAsPng(tfile, NewPngOptions())Case MimeTypes.WEBP tfile = Path.GetTempFileName() htmlPage.SaveAsWebp(tfile, NewWebpOptions())CaseElse'' For formats other than JPEG Or PNG, create a GcBitmap And render to itUsing bmp = NewGcBitmap(pixelSize.Width, pixelSize.Height, True, dpi, dpi) htmlPage.Render(bmp, NewPngOptions())SelectCase targetMimeCase MimeTypes.BMP bmp.SaveAsBmp(ms)Case MimeTypes.GIF bmp.SaveAsGif(ms)Case MimeTypes.TIFF bmp.SaveAsTiff(ms)Case MimeTypes.ICO bmp.SaveAsIco(ms, Nothing, IcoFrameEncoding.Png)CaseElseThrowNew Exception("Unexpected.")EndSelectEndUsingEndSelectEndUsing'' If a temp file was used, copy the created image from the temp file and clean up:IfNotString.IsNullOrEmpty(tfile) ThenUsing ts = File.OpenRead(tfile) ts.CopyTo(ms)EndUsingFile.Delete(tfile)EndIf'' Done. ms.Seek(0, SeekOrigin.Begin)Return msEndFunctionEndClass