DsImaging provides you an option to set the alignment of an image within its container using the ImageAlign class. This class provides you an option to center, scale, or stretch an image with respect to the bitmap.
To align an image at the center of its container:
C# |
Copy Code
|
---|---|
//Initialize GcBitmap GcBitmap origBmp = new GcBitmap(1000, 1000, true); //Create the graphics for the Bitmap GcBitmapGraphics g = origBmp.CreateGraphics(Color.AliceBlue); //Get the image and define the image rectangle var image = Image.FromFile(Path.Combine("Resources", "Images", "tudor.jpg")); var imgRec = new Rectangle(50, 50, image.Width + 100, image.Height + 100); g.FillRectangle(imgRec, Color.Gray); //Draw the image with "CenterImage" alignment mode g.DrawImage(image, imgRec, null, ImageAlign.CenterImage); //Save the image origBmp.SaveAsJpeg("AlignImageCenter.jpeg"); |