Beispiel #1
0
        /// <summary>
        /// Extracts the rectangular part of the image
        /// </summary>
        /// <param name="x">Left border of part</param>
        /// <param name="y">Top border of part</param>
        /// <param name="rectWidth">Width of part</param>
        /// <param name="rectHeight">Height of part</param>
        /// <returns>Part of image</returns>
        public KrecImage GetSubregion(int x, int y, int rectWidth, int rectHeight)
        {
            var sourceBytesPerLine = bytesPerLine;
            var bytesPerPixel      = format.BytesPerPixel();

            var newBytesPerLine = KrecImage.CalculateStride(rectWidth, format);

            var newImageData = new byte[rectHeight * newBytesPerLine];

            var sourceImageData = imageData;
            var sourceIdxDelta  = y * sourceBytesPerLine + x * bytesPerPixel;

            for (int rowIdx = 0, sourceIdx = sourceIdxDelta, targetIdx = 0;
                 rowIdx < rectHeight;
                 rowIdx++, sourceIdx += sourceBytesPerLine, targetIdx += newBytesPerLine)
            {
                Array.Copy(sourceImageData, sourceIdx, newImageData, targetIdx, rectWidth * bytesPerPixel);
            }

            return(new KrecImage(rectWidth, rectHeight, newBytesPerLine,
                                 horizontalResolution, verticalResolution, format, newImageData));
        }
Beispiel #2
0
 public KrecImage(KrecImage source, byte[] newImageData)
     : this(source, newImageData, source.Format)
 {
 }
Beispiel #3
0
 public KrecImage(KrecImage source, byte[] newImageData, KrecImagePixelFormat newKrecImagePixelFormat)
     : this(source.Width, source.Height, source.BytesPerLine, source.HorizontalResolution,
            source.VerticalResolution, newKrecImagePixelFormat, newImageData)
 {
 }