예제 #1
0
        /// <summary>
        /// Crops the image by the specified width/height
        /// </summary>
        /// <param name="Width">The width.</param>
        /// <param name="Height">The height.</param>
        /// <param name="VAlignment">The v alignment.</param>
        /// <param name="HAlignment">The h alignment.</param>
        /// <returns></returns>
        public SwiftBitmap Crop(int Width, int Height, Align VAlignment, Align HAlignment)
        {
            Contract.Requires <NullReferenceException>(InternalBitmap != null);
            Unlock();
            var TempRectangle = new System.Drawing.Rectangle();

            TempRectangle.Height = Height;
            TempRectangle.Width  = Width;
            TempRectangle.Y      = VAlignment == Align.Top ? 0 : this.Height - Height;
            if (TempRectangle.Y < 0)
            {
                TempRectangle.Y = 0;
            }
            TempRectangle.X = HAlignment == Align.Left ? 0 : this.Width - Width;
            if (TempRectangle.X < 0)
            {
                TempRectangle.X = 0;
            }
            var TempHolder = InternalBitmap.Clone(TempRectangle, InternalBitmap.PixelFormat);

            InternalBitmap.Dispose();
            InternalBitmap = TempHolder;
            this.Width     = Width;
            this.Height    = Height;
            return(this);
        }
예제 #2
0
        /// <summary>
        /// Resizes an SwiftBitmap to a certain height
        /// </summary>
        /// <param name="Width">New width for the final image</param>
        /// <param name="Height">New height for the final image</param>
        /// <param name="Quality">Quality of the resizing</param>
        /// <returns>This</returns>
        public SwiftBitmap Resize(int Width, int Height, Quality Quality = Quality.Low)
        {
            Contract.Requires <NullReferenceException>(InternalBitmap != null);
            Unlock();
            var TempBitmap = new Bitmap(Width, Height);

            using (Graphics NewGraphics = Graphics.FromImage(TempBitmap))
            {
                if (Quality == Quality.High)
                {
                    NewGraphics.CompositingQuality = CompositingQuality.HighQuality;
                    NewGraphics.SmoothingMode      = SmoothingMode.HighQuality;
                    NewGraphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                }
                else
                {
                    NewGraphics.CompositingQuality = CompositingQuality.HighSpeed;
                    NewGraphics.SmoothingMode      = SmoothingMode.HighSpeed;
                    NewGraphics.InterpolationMode  = InterpolationMode.NearestNeighbor;
                }
                NewGraphics.DrawImage(InternalBitmap, new System.Drawing.Rectangle(0, 0, Width, Height));
            }
            InternalBitmap.Dispose();
            InternalBitmap = TempBitmap;
            this.Width     = Width;
            this.Height    = Height;
            return(this);
        }
예제 #3
0
 /// <summary>
 /// Function to override in order to dispose objects
 /// </summary>
 /// <param name="Managed">
 /// If true, managed and unmanaged objects should be disposed. Otherwise unmanaged objects only.
 /// </param>
 protected override void Dispose(bool Managed)
 {
     if (Data != null)
     {
         Unlock();
     }
     if (InternalBitmap != null)
     {
         InternalBitmap.Dispose();
         InternalBitmap = null;
     }
 }
예제 #4
0
 /// <summary>
 /// Copies the image from one image to this one.
 /// </summary>
 /// <param name="SwiftBitmap">The SwiftBitmap to copy from.</param>
 /// <returns>This</returns>
 public unsafe SwiftBitmap Copy(SwiftBitmap SwiftBitmap)
 {
     Contract.Requires <NullReferenceException>(InternalBitmap != null);
     if (SwiftBitmap == null)
     {
         return(this);
     }
     Unlock();
     InternalBitmap.Dispose();
     InternalBitmap = (Bitmap)SwiftBitmap.InternalBitmap.Clone();
     return(this);
 }
예제 #5
0
        /// <summary>
        /// Rotates an image
        /// </summary>
        /// <param name="DegreesToRotate">Degrees to rotate the image</param>
        /// <returns>This</returns>
        public SwiftBitmap Rotate(float DegreesToRotate)
        {
            Contract.Requires <NullReferenceException>(InternalBitmap != null);
            Unlock();
            var TempBitmap = new Bitmap(Width, Height);

            using (Graphics NewGraphics = Graphics.FromImage(TempBitmap))
            {
                NewGraphics.TranslateTransform((float)Width / 2.0f, (float)Height / 2.0f);
                NewGraphics.RotateTransform(DegreesToRotate);
                NewGraphics.TranslateTransform(-(float)Width / 2.0f, -(float)Height / 2.0f);
                NewGraphics.DrawImage(InternalBitmap,
                                      new System.Drawing.Rectangle(0, 0, Width, Height),
                                      new System.Drawing.Rectangle(0, 0, Width, Height),
                                      GraphicsUnit.Pixel);
            }
            InternalBitmap.Dispose();
            InternalBitmap = TempBitmap;
            return(this);
        }