System.Drawing.Bitmap.UnlockBits C# (CSharp) Метод

UnlockBits() публичный метод

public UnlockBits ( BitmapData data ) : void
data BitmapData
Результат void
        public void UnlockBits(BitmapData data)
        {
            if (bitsLockMode == ImageLockMode.ReadOnly)
            {
                pinnedScanArray.Free ();
                bitsLockMode = 0;
                return;
            }

            //int destStride = data.Width * (NativeCGImage.BitsPerPixel / NativeCGImage.BitsPerComponent);
            int destStride = data.Stride;

            // Declare our size
            var scanLength  = destStride * Height;

            // This is fine here for now until we support other formats but right now it is RGBA
            var pixelSize = GetPixelFormatComponents (data.PixelFormat);

            if (pixelSize == 4)
                Convert_BGRA_8888_To_P_RGBA_8888 (data.Scan0, bitmapBlock, scanLength);
            else
                Convert_BGR_888_To_P_RGBA_8888 (data.Scan0, bitmapBlock, scanLength);

            // Create a bitmap context from the pixel data
            var bitmapContext = CreateCompatibleBitmapContext (data.Width, data.Height, data.PixelFormat, bitmapBlock);

            // Dispose of the prevous image that is allocated.
            NativeCGImage.Dispose ();

            // Get the image from the bitmap context.
            NativeCGImage = bitmapContext.ToImage ();

            // Dispose of the bitmap context as it is no longer needed
            bitmapContext.Dispose ();

            // we need to free our pointer
            pinnedScanArray.Free();
            bitsLockMode = 0;
        }

Usage Example

Пример #1
1
        public void AddFrame(Bitmap bmp)
        {
            bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);

            BitmapData bmpDat = bmp.LockBits(
                new Rectangle(0, 0, bmp.Width, bmp.Height),
                ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);

            if (countFrames == 0)
            {
                this.stride = (UInt32)bmpDat.Stride;
                this.width = bmp.Width;
                this.height = bmp.Height;
                CreateStream();
            }

            int result = AviReadingMethods.AVIStreamWrite(aviStream,
                countFrames, 1,
                bmpDat.Scan0,
                (Int32)(stride * height),
                0, 0, 0);

            if (result != 0)
            {
                throw new Exception("Problem podczas otwierania pliku AVI" + result.ToString());
            }

            bmp.UnlockBits(bmpDat);
            countFrames++;
        }
All Usage Examples Of System.Drawing.Bitmap::UnlockBits