'''' 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.ImagingImports GCTEXT = GrapeCity.Documents.Text '' This sample shows the results of enlarging a small (57 by 57 pixels) image'' of a QRCode using the 4 available interpolation modes.'' While for most images (such as portraits or landscapes), Linear or Cubic'' interpolation modes would normally yield better-looking results,'' for images like QRCodes or barcodes using the NearestNeighbor or'' Downscale modes is more appropriate.'''' See EnlargeImage for an example where a small photo (portrait of a woman)'' is enlarged using the same 4 interpolation modes.PublicClassEnlargeQRCodePublicFunctionGenerateImage(ByVal pixelSize AsSize,ByVal dpi AsSingle,ByVal opaque AsBoolean,OptionalByVal sampleParams AsString() = Nothing) AsGcBitmap '' Create and clear the target bitmap:Dim targetBmp = NewGcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi) targetBmp.Clear(Color.Transparent) ConstfontSizeAsInteger = 16Dim xpad AsInteger = CInt(dpi * 0.5F)Dim ypad AsInteger = CInt(dpi * 0.7F)Dim tf AsNewTextFormat() With { .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeSerif.ttf")), .FontSize = fontSize } '' Small image of a QRCode:Using origBmp AsNewGcBitmap()Using stm = File.OpenRead(Path.Combine("Resources", "ImagesBis", "QRCode-57x57.png")) origBmp.Load(stm)EndUsing '' Make sure opaqueness of the original bitmap matches the target: origBmp.Opaque = targetBmp.Opaque Dim ip AsNewPoint(xpad, ypad) '' Draw the original with the original size: targetBmp.BitBlt(origBmp, ip.X, ip.Y)Using g = targetBmp.CreateGraphics(Nothing) g.DrawString($"⟵ Original image ({origBmp.PixelWidth} by {origBmp.PixelHeight} pixels)", tf,NewPointF(xpad * 2 + origBmp.Width, ip.Y))EndUsing ip.Y += origBmp.PixelHeight + ypad '' We are going to enlarge the original small image by a factor of 6:Dim f AsInteger = 6Dim twidth AsInteger = origBmp.PixelWidth * fDim theight AsInteger = origBmp.PixelHeight * f '' Enlarge and draw 4 copies of the image using the 4 available interpolation modes:Using bmp = origBmp.Resize(twidth, theight, InterpolationMode.NearestNeighbor) targetBmp.BitBlt(bmp, ip.X, ip.Y)EndUsingdrawCaption(targetBmp, tf, "InterpolationMode.NearestNeighbor", ip.X, ip.Y + theight) Using bmp = origBmp.Resize(twidth, theight, InterpolationMode.Cubic) targetBmp.BitBlt(bmp, ip.X + twidth + xpad, ip.Y)EndUsingdrawCaption(targetBmp, tf, "InterpolationMode.Cubic", ip.X + twidth + xpad, ip.Y + theight) ip.Y += theight + ypad Using bmp = origBmp.Resize(twidth, theight, InterpolationMode.Linear) targetBmp.BitBlt(bmp, ip.X, ip.Y)EndUsingdrawCaption(targetBmp, tf, "InterpolationMode.Linear", ip.X, ip.Y + theight) Using bmp = origBmp.Resize(twidth, theight, InterpolationMode.Downscale) targetBmp.BitBlt(bmp, ip.X + twidth + xpad, ip.Y)EndUsingdrawCaption(targetBmp, tf, "InterpolationMode.Downscale", ip.X + twidth + xpad, ip.Y + theight)EndUsingReturn targetBmpEndFunction '' Local helper to draw captions:SubdrawCaption(ByRef targetBmp AsGcBitmap, ByRef tf AsTextFormat, ByVal caption AsString, ByVal x AsSingle, ByVal y AsSingle)Using g = targetBmp.CreateGraphics(Nothing) g.DrawString(caption, tf, NewPointF(x, y))EndUsingEndSubEndClass