当前位置: 首页>>代码示例>>C#>>正文


C# Bitmap.FastLock方法代码示例

本文整理汇总了C#中System.Drawing.Bitmap.FastLock方法的典型用法代码示例。如果您正苦于以下问题:C# Bitmap.FastLock方法的具体用法?C# Bitmap.FastLock怎么用?C# Bitmap.FastLock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Bitmap的用法示例。


在下文中一共展示了Bitmap.FastLock方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: captureTarget

 private void captureTarget()
 {
     int runX = x;
     int runY = y;
     Size runSize = new Size(width, height);
     while (this.running) {
         try {
             using (Bitmap screen = new Bitmap(runSize.Width, runSize.Height, PixelFormat.Format32bppArgb)) {
                 using (Graphics grphx = Graphics.FromImage(screen)) {
                     try {
                         grphx.CopyFromScreen(runX, runY, 0, 0, runSize, CopyPixelOperation.SourceCopy);
                         grphx.Save();
                         if (null != screen && NewScreenAvailEvent != null) {
                             NewScreenAvailEvent(screen.FastLock().DataArray, EventArgs.Empty);
                         }
                     }
                     catch (Exception e) {
                         Log(e.Message + '\t' + e.StackTrace);
                     }
                     Thread.Sleep(captureThrottle);
                 }
             }
         }
         catch (Exception ex) {
             Log(ex.Message + '\t' + ex.StackTrace);
         }
     }
 }
开发者ID:abigail3306,项目名称:wintumbra,代码行数:28,代码来源:AntumbraScreenGrabber.cs

示例2: CopyPixels

        /// <summary>
        /// Performs a copy operation of the pixels from the Source bitmap to the Target bitmap.
        /// If the dimensions or pixel depths of both images don't match, the copy is not performed
        /// </summary>
        /// <param name="source">The bitmap to copy the pixels from</param>
        /// <param name="target">The bitmap to copy the pixels to</param>
        /// <returns>Whether the copy proceedure was successful</returns>
        public static bool CopyPixels(Bitmap source, Bitmap target)
        {
            if (source.Width != target.Width || source.Height != target.Height || source.PixelFormat != target.PixelFormat)
                return false;

            using (FastBitmap fastSource = source.FastLock(),
                              fastTarget = target.FastLock())
            {
                memcpy(fastTarget.Scan0, fastSource.Scan0, (ulong)(fastSource.Height * fastSource._strideWidth * BytesPerPixel));
            }

            return true;
        }
开发者ID:Narinyir,项目名称:FastBitmap,代码行数:20,代码来源:FastBitmap.cs

示例3: ClearBitmap

 /// <summary>
 /// Clears the given bitmap with the given color
 /// </summary>
 /// <param name="bitmap">The bitmap to clear</param>
 /// <param name="color">The color to clear the bitmap with</param>
 public static void ClearBitmap(Bitmap bitmap, int color)
 {
     using (var fb = bitmap.FastLock())
     {
         fb.Clear(color);
     }
 }
开发者ID:Narinyir,项目名称:FastBitmap,代码行数:12,代码来源:FastBitmap.cs

示例4: CopyRegion

        /// <summary>
        /// Copies a region of the source bitmap into this fast bitmap
        /// </summary>
        /// <param name="source">The source image to copy</param>
        /// <param name="srcRect">The region on the source bitmap that will be copied over</param>
        /// <param name="destRect">The region on this fast bitmap that will be changed</param>
        /// <exception cref="ArgumentException">The provided source bitmap is the same bitmap locked in this FastBitmap</exception>
        public void CopyRegion(Bitmap source, Rectangle srcRect, Rectangle destRect)
        {
            // Throw exception when trying to copy same bitmap over
            if (source == _bitmap)
            {
                throw new ArgumentException("Copying regions across the same bitmap is not supported", "source");
            }

            Rectangle srcBitmapRect = new Rectangle(0, 0, source.Width, source.Height);
            Rectangle destBitmapRect = new Rectangle(0, 0, _width, _height);

            // Check if the rectangle configuration doesn't generate invalid states or does not affect the target image
            if (srcRect.Width <= 0 || srcRect.Height <= 0 || destRect.Width <= 0 || destRect.Height <= 0 ||
                !srcBitmapRect.IntersectsWith(srcRect) || !destRect.IntersectsWith(destBitmapRect))
                return;

            // Find the areas of the first and second bitmaps that are going to be affected
            srcBitmapRect = Rectangle.Intersect(srcRect, srcBitmapRect);

            // Clip the source rectangle on top of the destination rectangle in a way that clips out the regions of the original bitmap
            // that will not be drawn on the destination bitmap for being out of bounds
            srcBitmapRect = Rectangle.Intersect(srcBitmapRect, new Rectangle(srcRect.X, srcRect.Y, destRect.Width, destRect.Height));

            destBitmapRect = Rectangle.Intersect(destRect, destBitmapRect);

            // Clipt the source bitmap region yet again here
            srcBitmapRect = Rectangle.Intersect(srcBitmapRect, new Rectangle(-destRect.X + srcRect.X, -destRect.Y + srcRect.Y, _width, _height));

            // Calculate the rectangle containing the maximum possible area that is supposed to be affected by the copy region operation
            int copyWidth = Math.Min(srcBitmapRect.Width, destBitmapRect.Width);
            int copyHeight = Math.Min(srcBitmapRect.Height, destBitmapRect.Height);

            if (copyWidth == 0 || copyHeight == 0)
                return;

            int srcStartX = srcBitmapRect.Left;
            int srcStartY = srcBitmapRect.Top;

            int destStartX = destBitmapRect.Left;
            int destStartY = destBitmapRect.Top;

            using (FastBitmap fastSource = source.FastLock())
            {
                ulong strideWidth = (ulong)copyWidth * BytesPerPixel;

                for (int y = 0; y < copyHeight; y++)
                {
                    int destX = destStartX;
                    int destY = destStartY + y;

                    int srcX = srcStartX;
                    int srcY = srcStartY + y;

                    long offsetSrc = (srcX + srcY * fastSource._strideWidth);
                    long offsetDest = (destX + destY * _strideWidth);

                    memcpy(_scan0 + offsetDest, fastSource._scan0 + offsetSrc, strideWidth);
                }
            }
        }
开发者ID:Narinyir,项目名称:FastBitmap,代码行数:67,代码来源:FastBitmap.cs

示例5: TestCopyFromArrayMismatchedLengthException

        public void TestCopyFromArrayMismatchedLengthException()
        {
            Bitmap bitmap = new Bitmap(4, 4);

            FillBitmapRegion(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height), Color.Red);

            int[] colors =
            {
                0xFFFFFF, 0xFFFFEF, 0xABABAB, 0xABCDEF,
                0x111111, 0x123456, 0x654321, 0x000000,
                0x000000, 0xFFFFEF, 0x000000, 0xABCDEF,
                0x000000, 0x000000, 0x654321, 0x000000,
                0x000000, 0x000000, 0x654321, 0x000000
            };

            using (var fastBitmap = bitmap.FastLock())
            {
                fastBitmap.CopyFromArray(colors, true);
            }
        }
开发者ID:Narinyir,项目名称:FastBitmap,代码行数:20,代码来源:FastBitmapTests.cs

示例6: TestCopyFromArrayIgnoreZeroes

        public void TestCopyFromArrayIgnoreZeroes()
        {
            Bitmap bitmap = new Bitmap(4, 4);

            FillBitmapRegion(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height), Color.Red);

            int[] colors =
            {
                0xFFFFFF, 0xFFFFEF, 0xABABAB, 0xABCDEF,
                0x111111, 0x123456, 0x654321, 0x000000,
                0x000000, 0xFFFFEF, 0x000000, 0xABCDEF,
                0x000000, 0x000000, 0x654321, 0x000000
            };

            using (var fastBitmap = bitmap.FastLock())
            {
                fastBitmap.CopyFromArray(colors, true);
            }

            // Test now the resulting bitmap
            for (int y = 0; y < bitmap.Height; y++)
            {
                for (int x = 0; x < bitmap.Width; x++)
                {
                    int index = y * bitmap.Width + x;
                    int arrayColor = colors[index];
                    int bitmapColor = bitmap.GetPixel(x, y).ToArgb();

                    if(arrayColor != 0)
                    {
                        Assert.AreEqual(arrayColor, bitmapColor,
                            "After a call to CopyFromArray(_, true), the non-zeroes values provided on the on the array must match the values in the bitmap pixels");
                    }
                    else
                    {
                        Assert.AreEqual(Color.Red.ToArgb(), bitmapColor,
                            "After a call to CopyFromArray(_, true), the 0 values on the original array must not be copied over");
                    }
                }
            }
        }
开发者ID:Narinyir,项目名称:FastBitmap,代码行数:41,代码来源:FastBitmapTests.cs

示例7: TestCopyFromArray

        public void TestCopyFromArray()
        {
            Bitmap bitmap = new Bitmap(4, 4);
            int[] colors =
            {
                0xFFFFFF, 0xFFFFEF, 0xABABAB, 0xABCDEF,
                0x111111, 0x123456, 0x654321, 0x000000,
                0xFFFFFF, 0xFFFFEF, 0xABABAB, 0xABCDEF,
                0x111111, 0x123456, 0x654321, 0x000000
            };

            using (var fastBitmap = bitmap.FastLock())
            {
                fastBitmap.CopyFromArray(colors);
            }

            // Test now the resulting bitmap
            for (int y = 0; y < bitmap.Height; y++)
            {
                for (int x = 0; x < bitmap.Width; x++)
                {
                    int index = y * bitmap.Width + x;

                    Assert.AreEqual(colors[index], bitmap.GetPixel(x, y).ToArgb(),
                        "After a call to CopyFromArray, the values provided on the on the array must match the values in the bitmap pixels");
                }
            }
        }
开发者ID:Narinyir,项目名称:FastBitmap,代码行数:28,代码来源:FastBitmapTests.cs

示例8: TestLockExtensionMethod

        public void TestLockExtensionMethod()
        {
            Bitmap bitmap = new Bitmap(64, 64);

            using (FastBitmap fast = bitmap.FastLock())
            {
                fast.SetPixel(0, 0, Color.Red);
            }

            // Test unlocking by trying to modify the bitmap
            bitmap.SetPixel(0, 0, Color.Blue);
        }
开发者ID:Narinyir,项目名称:FastBitmap,代码行数:12,代码来源:FastBitmapTests.cs


注:本文中的System.Drawing.Bitmap.FastLock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。