Example #1
0
        public void Clip(int left, int top, int width, int height)
        {
            var rect = new WICRect();

            rect.X      = left;
            rect.Y      = top;
            rect.Width  = width;
            rect.Height = height;

            var clip = WICImagingFactory.CreateBitmapClipper();

            clip.Object.Initialize(_comObject.Object, ref rect).ThrowOnError();
            _comObject?.Dispose();
            _comObject = clip;
        }
Example #2
0
        public void CenterClip(int?width, int?height)
        {
            if (!width.HasValue && !height.HasValue)
            {
                return;
            }

            var rect = new WICRect();
            int w    = Width;
            int h    = Height;

            if (width.HasValue && width.Value < w)
            {
                rect.Width = width.Value;
                rect.X     = (w - width.Value) / 2;
            }
            else
            {
                rect.Width = w;
                rect.X     = 0;
            }

            if (height.HasValue && height.Value < h)
            {
                rect.Height = height.Value;
                rect.Y      = (h - height.Value) / 2;
            }
            else
            {
                rect.Height = h;
                rect.Y      = 0;
            }

            var clip = WICImagingFactory.CreateBitmapClipper();

            clip.Object.Initialize(_comObject.Object, ref rect).ThrowOnError();
            _comObject?.Dispose();
            _comObject = clip;
        }