//// 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;usingGCDRAW = GrapeCity.Documents.Drawing; namespaceDsImagingWeb.Demos{// This sample demonstrates how to use GcBitmap.AutoLevel()// to automatically adjust the output levels of an image.publicclassAutoLevels {publicGcBitmapGenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null) { opaque = true;var bmp = newGcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi);using (var origBmp = newGcBitmap()) {// Load a sample photo:var imagePath = Path.Combine("Resources", "ImagesBis", "red-yellow-wall.jpg");using (var stm = newFileStream(imagePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.RandomAccess)) origBmp.Load(stm); // Resize the original photo to fit two versions on the resulting bitmap:int w = pixelSize.Width;int h = pixelSize.Height / 2;using (var sizedBmp = origBmp.Resize(w, h, InterpolationMode.Cubic)) {// Copy the resized original into the upper half of the resulting bitmap: bmp.BitBlt(sizedBmp, 0, 0);// Auto adjust levels of the original and copy the result into the lower half: sizedBmp.AutoLevel(); bmp.BitBlt(sizedBmp, 0, h); } // Add captions (original and adjusted images):var lineh = 2;using (var g = bmp.CreateGraphics(null)) {var foreColor = Color.Yellow;var backColor = Color.Blue;var font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeMono.ttf")); g.DrawLine(0, h, w * 2, h, newGCDRAW.Pen(Color.Gray, lineh * 2));var tf = newTextFormat() { Font = font, FontSize = 18, ForeColor = foreColor, BackColor = backColor, FontBold = true };var th = g.MeasureString("QWERTY", tf).Height; g.DrawString(" Original image ", tf, newPointF(0, h - th + lineh)); g.DrawString(" Auto levels applied ", tf, newPointF(0, h * 2 + lineh - th + lineh)); } }return bmp; } }}