//// This code is part of Document Solutions for Imaging demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Imaging; namespaceDsImagingWeb.Demos{// This sample demonstrates the use of GcBitmap.GetContentRect() method// that allows trimming single colored margins off an image.publicclassGetContentRect {publicGcBitmapGenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null) {// The original goldfish image has white background with margins around the actual fish:var origImagePath = Path.Combine("Resources", "Stock", "goldfish.jpg"); // Create the resulting bitmap:var targetBmp = newGcBitmap(pixelSize.Width, pixelSize.Height, true, dpi, dpi);using (var origBmp = newGcBitmap()) {// Load the goldfish image:using (var stm = newFileStream(origImagePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.RandomAccess)) origBmp.Load(stm);// Create graphics on the resulting bitmap, filling it with blue color:using (var g = targetBmp.CreateGraphics(Color.FromArgb(unchecked((int)0xff004d99)))) {// Render the goldfish on white background: targetBmp.BitBlt(origBmp, 0, 0);// The GetContentRect() method returns the area of the image without// margins of the specified color (white in this case):var rc = origBmp.GetContentRect(Color.White);// Draw a red border on the content rectangle: g.DrawRectangle(rc, Color.Red); } }return targetBmp; } }}