'''' This code is part of Document Solutions for Imaging demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsSystem.Collections.GenericImportsSystem.LinqImportsSystem.NumericsImportsGrapeCity.Documents.DrawingImportsGrapeCity.Documents.TextImportsGrapeCity.Documents.ImagingImports GCTEXT = GrapeCity.Documents.Text '' This sample takes a color JPEG, And creates bilevel bitmaps from it'' using all available dithering methods. The resulting b/w images'' are added as frames to a multi-frame TIFF.'' The original color image Is added as the last page.PublicClassDitheringInTiffFunctionGenerateImageStream(ByVal targetMime AsString,ByVal pixelSize AsSize,ByVal dpi AsSingle,ByVal opaque AsBoolean,Optional sampleParams AsString() = Nothing) AsStream IfNot targetMime = MimeTypes.TIFF ThenThrowNew Exception("This sample only supports TIFF output format.")EndIf Dim pth = Path.Combine("Resources", "Images", "minerva.jpg")Dim fnt = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeMono.ttf"))Dim ms = NewMemoryStream()Using tw = NewGcTiffWriter(ms), bmp = NewGcBitmap(pth)'' Create text layout for labels:Dim tl = NewTextLayout(bmp.DpiX) tl.DefaultFormat.Font = fnt tl.DefaultFormat.FontSize = 16 tl.DefaultFormat.BackColor = Color.White'' Loop through all dithering methods (starting with no dithering):Dim methods = GetType(DitheringMethod).GetEnumValues()ForEach method AsDitheringMethodIn methodsUsing tbmp = bmp.Clone()'' Apply dithering: tbmp.ApplyEffect(DitheringEffect.Get(method))'' Draw label: tl.Clear() tl.Append(method.ToString()) tl.PerformLayout(True)Using g = tbmp.CreateGraphics() g.DrawTextLayout(tl, NewPointF(0, tbmp.Height - tl.ContentHeight))EndUsing'' Convert to bilevel bitmapUsing f = tbmp.ToBilevelBitmap() tw.AppendFrame(f)EndUsingEndUsingNext'' Add original image: tw.AppendFrame(bmp)EndUsing ms.Seek(0, SeekOrigin.Begin)Return msEndFunction PublicReadOnlyPropertyDefaultMime() AsStringGetReturn MimeTypes.TIFFEndGetEndPropertyEndClass