Example #1
0
        /// <summary>
        /// Creates an <see cref="EditableBitmap"/> as a view on a section of an existing <see cref="EditableBitmap"/>.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="viewArea"></param>
        protected EditableBitmap(EditableBitmap source, Rectangle viewArea)
        {
            owner           = source;
            pixelFormatSize = source.pixelFormatSize;
            byteArray       = source.byteArray;
            byteArray.AddReference();
            stride = source.stride;

            try
            {
                startOffset = source.startOffset + (stride * viewArea.Y) + (viewArea.X * pixelFormatSize);
                bitmap      = new Bitmap(viewArea.Width, viewArea.Height, stride, source.Bitmap.PixelFormat,
                                         (IntPtr)(((int)byteArray.bitPtr) + startOffset));
            }
            finally
            {
                if (bitmap == null)
                {
                    byteArray.ReleaseReference();
                }
            }
        }