//// 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 different grayscale effects. // See also MatrixEffects1 and MatrixEffects2.publicclassGrayscaleEffects {publicGcBitmapGenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null) { opaque = false;var bmp = newGcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi);using (var origBmp = newGcBitmap()) {// Load a sample photo:var imagePath = Path.Combine("Resources", "Images", "maple.jpg");using (var stm = newFileStream(imagePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.RandomAccess)) origBmp.Load(stm); origBmp.SetAlphaTo255(); origBmp.Opaque = false; // Resize the original photo so we can place 4 samples of it// on the resulting bitmap:int w = pixelSize.Width / 2;int h = pixelSize.Height / 2;using (var sizedBmp = origBmp.Resize(w, h, InterpolationMode.Cubic)) {// Copy the resized original into 4 quadrants of the resulting bitmap: bmp.BitBlt(sizedBmp, 0, 0); bmp.BitBlt(sizedBmp, w, 0); bmp.BitBlt(sizedBmp, 0, h); bmp.BitBlt(sizedBmp, w, h); } // Moving the 3 lines with the "ApplyEffect" comment from below to here// will apply the effects only to the photos but not to the texts. // Add borders between the quadrants, and captions for each: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(w, 0, w, h * 2, newGCDRAW.Pen(foreColor, lineh * 2)); g.DrawLine(0, h, w * 2, h, newGCDRAW.Pen(foreColor, lineh * 2));var tf = newTextFormat() { Font = font, FontSize = 18, ForeColor = foreColor, BackColor = backColor, FontBold = true }; g.DrawString(" Original image ", tf, newPointF(0, 0)); g.DrawString(" GrayscaleStandard.BT601 ", tf, newPointF(w + lineh, 0)); g.DrawString(" GrayscaleStandard.BT709 ", tf, newPointF(0, h + lineh)); g.DrawString(" GrayscaleStandard.BT2100 ", tf, newPointF(w + lineh, h + lineh)); }// ApplyEffect (move this code up to before drawing texts// to limit it to photos only and not affect the captions).//// Keep the pixels in top left quadrant intact,// apply effects to the other 3 quadrants: bmp.ApplyEffect(GrayscaleEffect.Get(GrayscaleStandard.BT601), newRectangle(w + lineh, 0, w - lineh, h - lineh)); bmp.ApplyEffect(GrayscaleEffect.Get(GrayscaleStandard.BT709), newRectangle(0, h + lineh, w - lineh, h - lineh)); bmp.ApplyEffect(GrayscaleEffect.Get(GrayscaleStandard.BT2100), newRectangle(w + lineh, h + lineh, w - lineh, h - lineh)); }return bmp; } }}