//// 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.Imaging; namespaceDsImagingWeb.Demos{// This sample demonstrates how to swap color channels on an image// using pixel access. Here we swap red and blue channels to// change the way the image looks.publicclassSwapColors {publicGcBitmapGenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null) {var bmp = newGcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi);using (var bmpSrc = newGcBitmap(Path.Combine("Resources", "ImagesBis", "alpamayo-sq.jpg"))) {// BitBlt requires the opacity of both images to be the same: bmpSrc.Opaque = opaque;// Render source image onto the target bitmap// (generally we might want to resize the source image first,// but in this case we just know that the source image has// the same size as the target, so skip this step): bmp.BitBlt(bmpSrc, 0, 0); using (var g = bmp.CreateGraphics()) {for (int i = 0; i < bmp.PixelWidth; ++i)for (int j = 0; j < bmp.PixelHeight; ++j) {#if bad_performance // Due to the number of pixels, it is better to optimize pixel operations var color = Color.FromArgb((int)bmp[i, j]); var t = color.B; color = Color.FromArgb(color.A, color.B, color.G, color.R); bmp[i, j] = (uint)color.ToArgb();#elseuint px = bmp[i, j]; px = ((px & 0x000000FF) << 16) | ((px & 0x00FF0000) >> 16) | (px & 0xFF00FF00); bmp[i, j] = px;#endif }// Draw the original image in the bottom right corner for reference:float sx = pixelSize.Width / 3, sy = pixelSize.Height / 3; g.DrawImage(bmpSrc, newRectangleF(sx * 2, sy * 2, sx, sy), null, ImageAlign.StretchImage); } }return bmp; } }}