コード例 #1
0
ファイル: FastBitmap.cs プロジェクト: mdrexel/ImageBird
        /// <summary>
        /// Performs the supplied <paramref name="operation"/> on the supplied <see cref="Bitmap"/> <paramref name="bitmap"/>.
        /// </summary>
        /// <param name="bitmap">
        /// The <see cref="Bitmap"/> to perform the operation on.
        /// </param>
        /// <param name="operation">
        /// The operation to perform on the contents of the supplied <see cref="Bitmap"/>.
        /// </param>
        /// <param name="lockMode">
        /// The locking mode for the <see cref="Bitmap"/>. Defaults to <see cref="ImageLockMode.ReadOnly"/>.
        /// </param>
        protected static unsafe void Operation(
            Bitmap bitmap,
            LockingDataOperation operation,
            ImageLockMode lockMode = ImageLockMode.ReadOnly)
        {
            BitmapData contents = bitmap.LockBits(
                new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                lockMode,
                bitmap.PixelFormat);

            try
            {
                operation(contents, (byte *)contents.Scan0.ToPointer());
            }
            finally
            {
                bitmap.UnlockBits(contents);
            }
        }
コード例 #2
0
        internal static unsafe void PerformLockingOperation(Bitmap bitmap, LockingDataOperation operation)
        {
            lock (bitmap)
            {
                BitmapData data = bitmap.LockBits(
                    new Rectangle(
                        0,
                        0,
                        bitmap.Width,
                        bitmap.Height),
                    ImageLockMode.ReadWrite,
                    bitmap.PixelFormat);

                try
                {
                    operation(data, (byte *)data.Scan0.ToPointer());
                }
                finally
                {
                    bitmap.UnlockBits(data);
                }
            }
        }