A clip region refers to a specific part of an image and is defined to limit the drawing operations for an image to a specific part of the image.
In DsImaging, the clip region can be created using the CreateClipRegion method of the GcBitmapGraphics class which takes a Rectangle or a GraphicsPath as a parameter. The defined clip region is applied to the image using the PushClip method which limits the drawing operations to the clip region. After the required drawing operations are done, you can use the PopClip method to remove the clip region and make the complete image surface available for any further drawing operations.
To clip an image:
C# |
Copy Code
|
---|---|
var backColor = Color.FromArgb(unchecked((int)0xff0066cc)); var foreColor = Color.FromArgb(unchecked((int)0xffffcc00)); float cw = 450, ch = 300, pad = 10, bord = 4; int pixelWidth = 1024, pixelHeight = 1024; GcBitmap origBmp = new GcBitmap(pixelWidth, pixelHeight, true); var path = Path.Combine("Resources", "Images", "tudor.jpg"); origBmp.Load(path); GcBitmapGraphics g = origBmp.CreateGraphics(); RectangleF clipRc = new RectangleF(pixelWidth - cw - pad, pad, cw, ch); using (g.PushClip(clipRc)) { g.FillRectangle(clipRc, Color.Blue); g.DrawString("This is a beautiful home", new TextFormat() { Font = Font.FromFile(Path.Combine("Resources", "Fonts", "times.ttf")), FontSize = 16, ForeColor = foreColor }, clipRc ); } //Save the image with clipped region origBmp.SaveAsJpeg("ClipImageTest.jpeg"); |
For more information about implementation of clipping using DsImaging, see DsImaging sample browser.