'''' This code is part of Document Solutions for Imaging demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsSystem.Collections.GenericImportsSystem.LinqImportsGrapeCity.Documents.DrawingImportsGrapeCity.Documents.TextImportsGrapeCity.Documents.Imaging '' This sample demonstrates the use of GcBitmap.GetContentRect() method'' that allows you to trim single colored margins off an image.PublicClassGetContentRectFunctionGenerateImage(ByVal pixelSize AsSize,ByVal dpi AsSingle,ByVal opaque AsBoolean,OptionalByVal sampleParams AsString() = Nothing) AsGcBitmap '' The original goldfish image has white background with margins around the actual fish:Dim origImagePath = Path.Combine("Resources", "Stock", "goldfish.jpg") '' Create the resulting bitmap:Dim targetBmp = NewGcBitmap(pixelSize.Width, pixelSize.Height, True, dpi, dpi)Using origBmp = NewGcBitmap()'' Load the goldfish image:Using stm = NewFileStream(origImagePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.RandomAccess) origBmp.Load(stm)EndUsing'' Create graphics on the resulting bitmap, filling it with blue color:Using g = targetBmp.CreateGraphics(Color.FromArgb(&HFF004D99))'' 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):Dim rc = origBmp.GetContentRect(Color.White)'' Draw a red border on the content rectangle: g.DrawRectangle(rc, Color.Red)EndUsingEndUsingReturn targetBmpEndFunctionEndClass