//// This code is part of Document Solutions for Imaging demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Drawing;usingGrapeCity.Documents.Text;usingGrapeCity.Documents.Imaging;usingGCTEXT = GrapeCity.Documents.Text; namespaceDsImagingWeb.Demos{// 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.publicclassEnlargeQRCode {publicGcBitmapGenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null) {// Create and clear the target bitmap:var targetBmp = newGcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi); targetBmp.Clear(Color.Transparent); constintfontSize = 16;var xpad = (int)(dpi * .5f);var ypad = (int)(dpi * .7f);TextFormat tf = newTextFormat {Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeSerif.ttf")),FontSize = fontSize, }; // Small image of a QRCode:usingvar origBmp = newGcBitmap();using (var stm = File.OpenRead(Path.Combine("Resources", "ImagesBis", "QRCode-57x57.png"))) origBmp.Load(stm); // Make sure opaqueness of the original bitmap matches the target: origBmp.Opaque = targetBmp.Opaque; var ip = newPoint(xpad, ypad); // Draw the original with the original size: targetBmp.BitBlt(origBmp, ip.X, ip.Y);using (var g = targetBmp.CreateGraphics(null)) g.DrawString($"⟵ Original image ({origBmp.PixelWidth} by {origBmp.PixelHeight} pixels)", tf, newPointF(xpad * 2 + origBmp.Width, ip.Y)); ip.Y += origBmp.PixelHeight + ypad; // We are going to enlarge the original small image by a factor of 6:var f = 6;int twidth = origBmp.PixelWidth * f;int theight = origBmp.PixelHeight * f; // Enlarge and draw 4 copies of the image using the 4 available interpolation modes:using (var bmp = origBmp.Resize(twidth, theight, InterpolationMode.NearestNeighbor)) targetBmp.BitBlt(bmp, ip.X, ip.Y);drawCaption("InterpolationMode.NearestNeighbor", ip.X, ip.Y + theight); using (var bmp = origBmp.Resize(twidth, theight, InterpolationMode.Cubic)) targetBmp.BitBlt(bmp, ip.X + twidth + xpad, ip.Y);drawCaption("InterpolationMode.Cubic", ip.X + twidth + xpad, ip.Y + theight); ip.Y += theight + ypad; using (var bmp = origBmp.Resize(twidth, theight, InterpolationMode.Linear)) targetBmp.BitBlt(bmp, ip.X, ip.Y);drawCaption("InterpolationMode.Linear", ip.X, ip.Y + theight); using (var bmp = origBmp.Resize(twidth, theight, InterpolationMode.Downscale)) targetBmp.BitBlt(bmp, ip.X + twidth + xpad, ip.Y);drawCaption("InterpolationMode.Downscale", ip.X + twidth + xpad, ip.Y + theight);//voiddrawCaption(string caption, float x, float y) {usingvar g = targetBmp.CreateGraphics(null); g.DrawString(caption, tf, newPointF(x, y)); }return targetBmp; } }}