'''' This code is part of Document Solutions for Imaging demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystemImportsSystem.IOImportsSystem.DrawingImportsSystem.Collections.GenericImportsSystem.LinqImportsGrapeCity.Documents.DrawingImportsGrapeCity.Documents.TextImportsGrapeCity.Documents.ImagingImportsGrapeCity.Documents.Imaging.SkiaImportsGrapeCity.Documents.Imaging.WindowsImports GCTEXT = GrapeCity.Documents.Text '' This example demonstrates the differences in fidelity between texts'' rendered on bitmaps using the different DsImaging libraries:'' - DsImaging (cross-platform, package GrapeCity.Documents.Imaging);'' - DsImaging.Skia (cross-platform, package GrapeCity.Documents.Imaging.Skia);'' - DsImaging.Windows (Windows only, package GrapeCity.Documents.Imaging.Windows).'' Note that the results are rather noticeable here because the text is rendered'' using a very small font, and then significantly enlarged when drawn on the'' resulting image generated by the sample. In most real-life applications'' the differences are very subtle if noticeable at all.PublicClassGcLibsComparisonPublicFunctionGenerateImage(ByVal pixelSize AsSize,ByVal dpi AsSingle,ByVal opaque AsBoolean,OptionalByVal sampleParams AsString() = Nothing) AsGcBitmap ConsttextAsString = "Skia is an open source 2D graphics library which provides common APIs that work across a variety of hardware and software platforms."Dim q AsInteger = 4Dim width AsInteger = pixelSize.Width \ qDim height AsInteger = pixelSize.Height \ (q * 3)Dim margin AsInteger = 12Dim tf AsNewTextFormat() With { .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeSans.ttf")), .FontSize = 10 }Dim msg AsString = $"Text with font size {tf.FontSize} rendered using {{0}} and enlarged x{q}:" Using gcBmp AsNewGcBitmap(width, height, False)Using g = gcBmp.CreateGraphics(Color.Transparent)Dim tl = g.CreateTextLayout() tl.MaxWidth = width tl.MarginAll = margin tl.Append(text, tf) g.DrawTextLayout(tl, PointF.Empty)EndUsing Using gcSkiaBmp AsNewGcSkiaBitmap(width, height, False)Using g = gcSkiaBmp.CreateGraphics(Color.Transparent)Dim tl = g.CreateTextLayout() tl.MaxWidth = width tl.MarginAll = margin tl.Append(text, tf) g.DrawTextLayout(tl, PointF.Empty)EndUsing Dim gcWicBmp AsGcWicBitmap = NothingIfGcWicBitmap.IsSupportedThen gcWicBmp = NewGcWicBitmap(width, height, False)Using g = gcWicBmp.CreateGraphics(Color.Transparent)Dim tl = g.CreateTextLayout() tl.MaxWidth = width tl.MarginAll = margin tl.Append(text, tf) g.DrawTextLayout(tl, PointF.Empty)EndUsingEndIf Dim bmp AsNewGcBitmap(pixelSize.Width, pixelSize.Height, opaque)Using g = bmp.CreateGraphics(Color.White) g.Renderer.InterpolationMode = InterpolationMode.NearestNeighborDim fs AsInteger = 16Dim dy AsInteger = pixelSize.Height \ 3 tf.FontSize = fs g.DrawString(String.Format(msg, "GcBitmapGraphics (cross-platform)"), tf, NewPointF(margin / 3.0F, margin / 3.0F))Dim rc AsNewRectangleF(0, fs * 2, width * q, height * q - fs * 2) rc.Inflate(-margin, -margin) g.DrawImage(gcBmp, rc, Nothing, ImageAlign.StretchImage) g.DrawRoundRect(rc, margin, Color.MediumVioletRed) g.DrawString(String.Format(msg, "GcSkiaGraphics (cross-platform)"), tf, NewPointF(margin / 3.0F, dy + margin / 3.0F)) rc = NewRectangleF(0, fs * 2 + dy, width * q, height * q - fs * 2) rc.Inflate(-margin, -margin) g.DrawImage(gcSkiaBmp, rc, Nothing, ImageAlign.StretchImage) g.DrawRoundRect(rc, margin, Color.MediumVioletRed) g.DrawString(String.Format(msg, "GcWicBitmapGraphics (Windows-only)"), tf, NewPointF(margin / 3.0F, dy * 2 + margin / 3.0F)) rc = NewRectangleF(0, fs * 2 + dy * 2, width * q, height * q - fs * 2) rc.Inflate(-margin, -margin)If gcWicBmp IsNotNothingThen g.DrawImage(gcWicBmp, rc, Nothing, ImageAlign.StretchImage)ElseDim tl = g.CreateTextLayout() tl.MaxWidth = rc.Width tl.MarginAll = margin tl.DefaultFormat.Font = tf.Font tl.DefaultFormat.FontSize = 16 tl.DefaultFormat.ForeColor = Color.OrangeRed tl.AppendLine("Looks like this demo is not running on a Windows system, so WIC (GcWicBitmap, GcWicBitmapGraphics) " &"is not supported. To see how text rendered using GcWicBitmapGraphics looks, download this demo project " &"and run it on a Windows system.") g.DrawTextLayout(tl, rc.Location)EndIf g.DrawRoundRect(rc, margin, Color.MediumVioletRed)EndUsing If gcWicBmp IsNotNothingThen gcWicBmp.Dispose()EndIf Return bmpEndUsingEndUsingEndFunctionEndClass