Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ImageBase{TColor}"/> class.
        /// </summary>
        /// <param name="other">
        /// The other <see cref="ImageBase{TColor}"/> to create this instance from.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown if the given <see cref="ImageBase{TColor}"/> is null.
        /// </exception>
        protected ImageBase(ImageBase <TColor> other)
        {
            Guard.NotNull(other, nameof(other), "Other image cannot be null.");

            this.Width  = other.Width;
            this.Height = other.Height;
            this.CopyProperties(other);

            // Copy the pixels. Unsafe.CopyBlock gives us a nice speed boost here.
            this.pixelBuffer = new TColor[this.Width * this.Height];
            using (PixelAccessor <TColor> sourcePixels = other.Lock())
                using (PixelAccessor <TColor> target = this.Lock())
                {
                    sourcePixels.CopyTo(target);
                }
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ImageBase{TColor}"/> class.
        /// </summary>
        /// <param name="other">
        /// The other <see cref="ImageBase{TColor}"/> to create this instance from.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown if the given <see cref="ImageBase{TColor}"/> is null.
        /// </exception>
        protected ImageBase(ImageBase <TColor> other)
        {
            Guard.NotNull(other, nameof(other), "Other image cannot be null.");

            this.Width  = other.Width;
            this.Height = other.Height;
            this.CopyProperties(other);

            // Rent then copy the pixels. Unsafe.CopyBlock gives us a nice speed boost here.
            this.RentPixels();
            using (PixelAccessor <TColor> sourcePixels = other.Lock())
                using (PixelAccessor <TColor> target = this.Lock())
                {
                    // Check we can do this without crashing
                    sourcePixels.CopyTo(target);
                }
        }