• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Drawing.FastBitmap类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



FastBitmap类属于System.Drawing命名空间,在下文中一共展示了FastBitmap类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetColorCount

        /// <summary>
        /// Returns the color count from the palette of the given image.
        /// </summary>
        /// <param name="image">
        /// The <see cref="System.Drawing.Image"/> to get the colors from.
        /// </param>
        /// <returns>
        /// The <see cref="int"/> representing the color count.
        /// </returns>
        public static int GetColorCount(Image image)
        {
            ConcurrentDictionary<Color, Color> colors = new ConcurrentDictionary<Color, Color>();
            int width = image.Width;
            int height = image.Height;

            using (FastBitmap fastBitmap = new FastBitmap(image))
            {
                Parallel.For(
                    0,
                    height,
                    y =>
                    {
                        for (int x = 0; x < width; x++)
                        {
                            // ReSharper disable once AccessToDisposedClosure
                            Color color = fastBitmap.GetPixel(x, y);
                            colors.TryAdd(color, color);
                        }
                    });
            }

            int count = colors.Count;
            colors.Clear();
            return count;
        }
开发者ID:GertyEngrie,项目名称:ImageProcessor,代码行数:35,代码来源:FormatUtilities.cs


示例2: ProcessFilter

        /// <summary>
        /// Processes the given bitmap to apply the threshold.
        /// </summary>
        /// <param name="source">
        /// The image to process.
        /// </param>
        /// <returns>
        /// A processed bitmap.
        /// </returns>
        public Bitmap ProcessFilter(Bitmap source)
        {
            int width = source.Width;
            int height = source.Height;

            using (FastBitmap sourceBitmap = new FastBitmap(source))
            {
                Parallel.For(
                    0, 
                    height, 
                    y =>
                    {
                        for (int x = 0; x < width; x++)
                        {
                            // ReSharper disable AccessToDisposedClosure
                            Color color = sourceBitmap.GetPixel(x, y);
                            sourceBitmap.SetPixel(x, y, color.B >= this.threshold ? Color.White : Color.Black);

                            // ReSharper restore AccessToDisposedClosure
                        }
                    });
            }

            return source;
        }
开发者ID:AlexSkarbo,项目名称:ImageProcessor,代码行数:34,代码来源:BinaryThreshold.cs


示例3: CountColors

        public static int CountColors(this Image image)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }

            HashSet<int> colors = new HashSet<int>();

            FastBitmap fastBitmap = new FastBitmap(image);
            fastBitmap.Lock();

            // Loop through all the pixels of the image
            // and add the colors to the HashSet - duplicates
            // are automatically ignored by that collection type
            for (int x = 0; x < image.Width; x++)
            {
                for (int y = 0; y < image.Height; y++)
                {
                    // We use ToArgb because Colors are compared on more than their ARGB values - see Color class documentation on MSDN
                    colors.Add(fastBitmap.GetPixel(x, y).ToArgb());
                }
            }

            fastBitmap.Unlock();

            return colors.Count;
        }
开发者ID:jakepetroules,项目名称:jakes-3d-mmo,代码行数:28,代码来源:ImageExtensions.cs


示例4: Alpha

        /// <summary>
        /// Adjusts the alpha component of the given image.
        /// </summary>
        /// <param name="source">
        /// The <see cref="Image"/> source to adjust.
        /// </param>
        /// <param name="percentage">
        /// The percentage value between 0 and 100 for adjusting the opacity.
        /// </param>
        /// <param name="rectangle">The rectangle to define the bounds of the area to adjust the opacity. 
        /// If null then the effect is applied to the entire image.</param>
        /// <returns>
        /// The <see cref="Bitmap"/> with the alpha component adjusted.
        /// </returns>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Thrown if the percentage value falls outside the acceptable range.
        /// </exception>
        public static Bitmap Alpha(Image source, int percentage, Rectangle? rectangle = null)
        {
            if (percentage > 100 || percentage < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(percentage), "Percentage should be between 0 and 100.");
            }

            float factor = (float)percentage / 100;
            int width = source.Width;
            int height = source.Height;

            // Traditional examples using a color matrix alter the rgb values also.
            using (FastBitmap bitmap = new FastBitmap(source))
            {
                // Loop through the pixels.
                Parallel.For(
                    0,
                    height,
                    y =>
                    {
                        for (int x = 0; x < width; x++)
                        {
                            // ReSharper disable AccessToDisposedClosure
                            Color color = bitmap.GetPixel(x, y);
                            bitmap.SetPixel(x, y, Color.FromArgb(Convert.ToInt32(color.A * factor), color.R, color.G, color.B));
                            // ReSharper restore AccessToDisposedClosure
                        }
                    });
            }

            return (Bitmap)source;
        }
开发者ID:CastleSoft,项目名称:ImageProcessor,代码行数:49,代码来源:Adjustments.cs


示例5: TestFastBitmapCreation

        public void TestFastBitmapCreation()
        {
            Bitmap bitmap = new Bitmap(64, 64);
            FastBitmap fastBitmap = new FastBitmap(bitmap);
            fastBitmap.Lock();
            fastBitmap.Unlock();

            // Try creating a FastBitmap with different 32bpp depths
            try
            {
                // ReSharper disable once ObjectCreationAsStatement
                new FastBitmap(new Bitmap(1, 1, PixelFormat.Format32bppArgb));
                // ReSharper disable once ObjectCreationAsStatement
                new FastBitmap(new Bitmap(1, 1, PixelFormat.Format32bppPArgb));
                // ReSharper disable once ObjectCreationAsStatement
                new FastBitmap(new Bitmap(1, 1, PixelFormat.Format32bppRgb));
            }
            catch (ArgumentException)
            {
                Assert.Fail("The FastBitmap should accept any type of 32bpp pixel format bitmap");
            }

            // Try creating a FastBitmap with a bitmap of a bit depth different from 32bpp
            Bitmap invalidBitmap = new Bitmap(64, 64, PixelFormat.Format4bppIndexed);

            // ReSharper disable once ObjectCreationAsStatement
            new FastBitmap(invalidBitmap);
        }
开发者ID:Narinyir,项目名称:FastBitmap,代码行数:28,代码来源:FastBitmapTests.cs


示例6: ApplyMask

        /// <summary>
        /// Applies the given image mask to the source.
        /// </summary>
        /// <param name="source">
        /// The source <see cref="Image"/>.
        /// </param>
        /// <param name="mask">
        /// The mask <see cref="Image"/>.
        /// </param>
        /// <exception cref="ArgumentException">
        /// Thrown if the two images are of different size.
        /// </exception>
        /// <returns>
        /// The masked <see cref="Bitmap"/>.
        /// </returns>
        public static Bitmap ApplyMask(Image source, Image mask)
        {
            if (mask.Size != source.Size)
            {
                throw new ArgumentException();
            }

            int width = mask.Width;
            int height = mask.Height;

            Bitmap toMask = new Bitmap(source);
            toMask.SetResolution(source.HorizontalResolution, source.VerticalResolution);

            // Loop through and replace the alpha channel
            using (FastBitmap maskBitmap = new FastBitmap(mask))
            {
                using (FastBitmap sourceBitmap = new FastBitmap(toMask))
                {
                    Parallel.For(
                        0,
                        height,
                        y =>
                        {
                            for (int x = 0; x < width; x++)
                            {
                                // ReSharper disable AccessToDisposedClosure
                                Color maskColor = maskBitmap.GetPixel(x, y);
                                Color sourceColor = sourceBitmap.GetPixel(x, y);

                                if (sourceColor.A != 0)
                                {
                                    sourceBitmap.SetPixel(x, y, Color.FromArgb(maskColor.A, sourceColor.R, sourceColor.G, sourceColor.B));
                                }

                                // ReSharper restore AccessToDisposedClosure
                            }
                        });
                }
            }

            // Ensure the background is cleared out on non alpha supporting formats.
            Bitmap clear = new Bitmap(width, height, PixelFormat.Format32bppPArgb);
            clear.SetResolution(source.HorizontalResolution, source.VerticalResolution);
            using (Graphics graphics = Graphics.FromImage(clear))
            {
                graphics.SmoothingMode = SmoothingMode.AntiAlias;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.Clear(Color.Transparent);

                graphics.DrawImageUnscaled(toMask, 0, 0, width, height);
            }

            toMask.Dispose();
            return clear;
        }
开发者ID:CastleSoft,项目名称:ImageProcessor,代码行数:72,代码来源:Effects.cs


示例7: Apply

        public void Apply(FastBitmap surface, Rectangle[] roi, int startIndex, int length)
        {
            Rectangle regionBounds = Utility.GetRegionBounds (roi, startIndex, length);

            if (regionBounds != Rectangle.Intersect (surface.GetBounds (), regionBounds))
                throw new ArgumentOutOfRangeException ("roi", "Region is out of bounds");

            unsafe {
                for (int x = startIndex; x < startIndex + length; ++x)
                    ApplyRectangle (surface, roi[x]);
            }
        }
开发者ID:garuma,项目名称:apachai,代码行数:12,代码来源:UnaryPixelOp.cs


示例8: RenderEffect

        protected unsafe virtual void RenderEffect(FastBitmap src, FastBitmap dst, Rectangle roi)
        {
            PixelData* src_data_ptr = (PixelData*)src.DataPtr;
            int src_width = src.Width;
            PixelData* dst_data_ptr = (PixelData*)dst.DataPtr;
            int dst_width = dst.Width;

            for (int y = roi.Y; y < roi.Bottom; ++y) {
                PixelData* srcPtr = src.GetPointAddressUnchecked (src_data_ptr, src_width, roi.X, y);
                PixelData* dstPtr = dst.GetPointAddressUnchecked (dst_data_ptr, dst_width, roi.X, y);
                RenderLine (srcPtr, dstPtr, roi.Width);
            }
        }
开发者ID:garuma,项目名称:apachai,代码行数:13,代码来源:BaseEffect.cs


示例9: ApplyBase

        /// <summary>
        /// Provides a default implementation for performing dst = F(dst, src) or F(src) over some rectangle 
        /// of interest. May be slightly faster than calling the other multi-parameter Apply method, as less 
        /// variables are used in the implementation, thus inducing less register pressure.
        /// </summary>
        /// <param name="dst">The Surface to write pixels to, and from which pixels are read and used as the lhs parameter for calling the method <b>PixelData Apply(PixelData, PixelData)</b>.</param>
        /// <param name="dstOffset">The pixel offset that defines the upper-left of the rectangle-of-interest for the dst Surface.</param>
        /// <param name="src">The Surface to read pixels from for the rhs parameter given to the method <b>PixelData Apply(PixelData, PixelData)</b>b>.</param></param>
        /// <param name="srcOffset">The pixel offset that defines the upper-left of the rectangle-of-interest for the src Surface.</param>
        /// <param name="roiSize">The size of the rectangles-of-interest for all Surfaces.</param>
        public void ApplyBase(FastBitmap dst, Point dstOffset, FastBitmap src, Point srcOffset, Size roiSize)
        {
            // Create bounding rectangles for each Surface
            Rectangle dstRect = new Rectangle (dstOffset, roiSize);

            if (dstRect.Width == 0 || dstRect.Height == 0)
                return;

            Rectangle srcRect = new Rectangle (srcOffset, roiSize);

            if (srcRect.Width == 0 || srcRect.Height == 0)
                return;

            // Clip those rectangles to those Surface's bounding rectangles
            Rectangle dstClip = Rectangle.Intersect (dstRect, dst.GetBounds ());
            Rectangle srcClip = Rectangle.Intersect (srcRect, src.GetBounds ());

            // If any of those Rectangles actually got clipped, then throw an exception
            if (dstRect != dstClip)
                throw new ArgumentOutOfRangeException
                (
                    "roiSize",
                    "Destination roi out of bounds" +
                    string.Format (", dst.Size=({0},{1}", dst.Width, dst.Height) +
                    ", dst.Bounds=" + dst.GetBounds ().ToString () +
                    ", dstOffset=" + dstOffset.ToString () +
                    string.Format (", src.Size=({0},{1}", src.Width, src.Height) +
                    ", srcOffset=" + srcOffset.ToString () +
                    ", roiSize=" + roiSize.ToString () +
                    ", dstRect=" + dstRect.ToString () +
                    ", dstClip=" + dstClip.ToString () +
                    ", srcRect=" + srcRect.ToString () +
                    ", srcClip=" + srcClip.ToString ()
                );

            if (srcRect != srcClip)
                throw new ArgumentOutOfRangeException ("roiSize", "Source roi out of bounds");

            // Cache the width and height properties
            int width = roiSize.Width;
            int height = roiSize.Height;

            // Do the work.
            unsafe {
                for (int row = 0; row < roiSize.Height; ++row) {
                    PixelData* dstPtr = dst.GetPointAddress (dstOffset.X, dstOffset.Y + row);
                    PixelData* srcPtr = src.GetPointAddress (srcOffset.X, srcOffset.Y + row);
                    Apply (dstPtr, srcPtr, width);
                }
            }
        }
开发者ID:garuma,项目名称:apachai,代码行数:61,代码来源:PixelOp.cs


示例10: Atlas2dInto1d

        //tiles = 16 means 16 x 16 atlas
        public List<Bitmap> Atlas2dInto1d(Bitmap atlas2d, int tiles, int atlassizezlimit)
        {
            FastBitmap orig = new FastBitmap();
            orig.bmp = atlas2d;

            int tilesize = atlas2d.Width / tiles;

            int atlasescount = Math.Max(1, (tiles * tiles * tilesize) / atlassizezlimit);
            List<Bitmap> atlases = new List<Bitmap>();

            orig.Lock();

            //256 x 1
            FastBitmap atlas1d = null;

            for (int i = 0; i < tiles * tiles; i++)
            {
                int x = i % tiles;
                int y = i / tiles;
                int tilesinatlas = (tiles * tiles / atlasescount);
                if (i % tilesinatlas == 0)
                {
                    if (atlas1d != null)
                    {
                        atlas1d.Unlock();
                        atlases.Add(atlas1d.bmp);
                    }
                    atlas1d = new FastBitmap();
                    atlas1d.bmp = new Bitmap(tilesize, atlassizezlimit);
                    atlas1d.Lock();
                }
                for (int xx = 0; xx < tilesize; xx++)
                {
                    for (int yy = 0; yy < tilesize; yy++)
                    {
                        int c = orig.GetPixel(x * tilesize + xx, y * tilesize + yy);
                        atlas1d.SetPixel(xx, (i % tilesinatlas) * tilesize + yy, c);
                    }
                }
            }
            atlas1d.Unlock();
            atlases.Add(atlas1d.bmp);
            orig.Unlock();
            return atlases;
        }
开发者ID:cilution,项目名称:digger-stole-my-bike,代码行数:46,代码来源:TextureAtlasConverter.cs


示例11: DrawImage

        public Bitmap DrawImage(Color[] colors)
        {
            if (Width < 1 || Height < 1) {
                return null;
            }

            var image = new Bitmap(Width, Height);
            var fastBmp = new FastBitmap(image);

            fastBmp.LockImage();
            for (int y = 0, i = 0; y < Height; y++) {
                for (var x = 0; x < Width; x++) {
                    fastBmp.SetPixel(x, y, colors[(int)Cells[i++].Type]);
                }
            }
            fastBmp.UnlockImage();

            return image;
        }
开发者ID:GodLesZ,项目名称:ZeusEngine,代码行数:19,代码来源:Format.cs


示例12: TestSequentialFastBitmapLocking

        public void TestSequentialFastBitmapLocking()
        {
            Bitmap bitmap = new Bitmap(64, 64);
            FastBitmap fastBitmap = new FastBitmap(bitmap);

            Assert.IsFalse(fastBitmap.Locked, "Immediately after creation, the FastBitmap.Locked property must be false");

            fastBitmap.Lock();

            Assert.IsTrue(fastBitmap.Locked, "After a successful call to .Lock(), the .Locked property must be true");

            fastBitmap.Unlock();

            Assert.IsFalse(fastBitmap.Locked, "After a successful call to .Lock(), the .Locked property must be false");

            fastBitmap = new FastBitmap(bitmap);
            fastBitmap.Lock();
            fastBitmap.Unlock();
        }
开发者ID:Narinyir,项目名称:FastBitmap,代码行数:19,代码来源:FastBitmapTests.cs


示例13: DrawImage

		public Bitmap DrawImage(Color[] Colors) {
			if (Width < 1 || Height < 1) {
				return null;
			}

			Bitmap Image = new Bitmap(Width, Height);
			FastBitmap fastBmp = new FastBitmap(Image);

			using (Graphics g = Graphics.FromImage(Image)) {

				fastBmp.LockImage();
				for (int y = 0, i = 0; y < Height; y++) {
					for (int x = 0; x < Width; x++) {
						fastBmp.SetPixel(x, y, Colors[(int)Cells[i++].Type]);
					}
				}
				fastBmp.UnlockImage();
			}

			return Image;
		}
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:21,代码来源:RoGatFile.cs


示例14: CompareColors

        public static bool CompareColors(this Image image, Image other)
        {
            if (image == null || other == null)
            {
                throw new ArgumentNullException(image == null ? "image" : "other");
            }

            if (image.Size != other.Size)
            {
                return false;
            }

            FastBitmap fastImage = new FastBitmap(image);
            FastBitmap fastOther = new FastBitmap(other);

            try
            {
                fastImage.Lock();
                fastOther.Lock();

                for (int x = 0; x < image.Width; x++)
                {
                    for (int y = 0; y < image.Height; y++)
                    {
                        // We use ToArgb because Colors are compared on more than their ARGB values - see Color class documentation on MSDN
                        if (fastImage.GetPixel(x, y).ToArgb() != fastOther.GetPixel(x, y).ToArgb())
                        {
                            return false;
                        }
                    }
                }
            }
            finally
            {
                fastImage.Unlock();
                fastOther.Unlock();
            }

            return true;
        }
开发者ID:jakepetroules,项目名称:jakes-3d-mmo,代码行数:40,代码来源:ImageExtensions.cs


示例15: GenerateBitmap

        public static void GenerateBitmap(byte[] data, FastBitmap bmp, int startY, int dataAddress, List<Color> fourColors, int addY)
        {
            int index = 0;
            bool onlyHalf = false;
            int y = startY;
            int x = 0;
            int colorZeroValue = fourColors[0].ToArgb();
            while (y < bmp.Height && dataAddress + index + 2 < data.Length)
            {
                int runLength;
                int color;
                bool restOfLine;
                index += DecodeRle(dataAddress + index, data, out color, out runLength, ref onlyHalf, out restOfLine);
                if (restOfLine)
                    runLength = bmp.Width - x;

                Color c = fourColors[color]; // set color via the four colors
                for (int i = 0; i < runLength; i++, x++)
                {
                    if (x >= bmp.Width-1)
                    {
                        if (y < bmp.Height && x < bmp.Width && c != fourColors[0])
                            bmp.SetPixel(x, y, c);

                        if (onlyHalf)
                        {
                            onlyHalf = false;
                            index++;
                        }
                        x = 0;
                        y += addY;
                        break;
                    }
                    if (y < bmp.Height && c.ToArgb() != colorZeroValue)
                       bmp.SetPixel(x, y, c);
                }
            }
        }
开发者ID:nguansak,项目名称:subtitleedit,代码行数:38,代码来源:SubPicture.cs


示例16: ApplyAnimation

        unsafe void ApplyAnimation( AnimationData data )
        {
            data.Tick--;
            if( data.Tick >= 0 ) return;
            data.CurrentState++;
            data.CurrentState %= data.StatesCount;
            data.Tick = data.TickDelay;

            TerrainAtlas1D atlas = game.TerrainAtlas1D;
            int texId = ( data.TileY << 4 ) | data.TileX;
            int index = atlas.Get1DIndex( texId );
            int rowNum = atlas.Get1DRowId( texId );

            int size = data.FrameSize;
            byte* temp = stackalloc byte[size * size * 4];
            FastBitmap part = new FastBitmap( size, size, size * 4, (IntPtr)temp );
            FastBitmap.MovePortion( data.FrameX + data.CurrentState * size, data.FrameY, 0, 0, fastBmp, part, size );
            api.UpdateTexturePart( atlas.TexIds[index], 0, rowNum * game.TerrainAtlas.elementSize, part );
        }
开发者ID:umby24,项目名称:ClassicalSharp,代码行数:19,代码来源:Animations.cs


示例17: ProcessFrame

        /// <summary>
        ///   Performs object detection on the given frame.
        /// </summary>
        /// 
        //public Rectangle[] ProcessFrame(Bitmap frame)
        //{
        //    using (FastBitmap fastBitmap = new FastBitmap(frame))
        //    {
        //        return ProcessFrame(fastBitmap);
        //    }
        //}

        /// <summary>
        ///   Performs object detection on the given frame.
        /// </summary>
        /// 
        public Rectangle[] ProcessFrame(Bitmap image)
        {
          //  int colorChannel =
           //   image.PixelFormat == PixelFormat.Format8bppIndexed ? 0 : channel;

            Rectangle[] objects;

            // Creates an integral image representation of the frame
            using (FastBitmap fastBitmap = new FastBitmap(image, this.classifier.Cascade.HasTiltedFeatures))
            {
                // Creates a new list of detected objects.
                this.detectedObjects.Clear();

                int width = fastBitmap.Width;
                int height = fastBitmap.Height;

                // Update parameters only if different size
                if (steps == null || width != lastWidth || height != lastHeight)
                    update(width, height);


                Rectangle window = Rectangle.Empty;

                // For each scaling step
                for (int i = 0; i < steps.Length; i++)
                {
                    float scaling = steps[i];

                    // Set the classifier window scale
                    classifier.Scale = scaling;

                    // Get the scaled window size
                    window.Width = (int)(baseWidth * scaling);
                    window.Height = (int)(baseHeight * scaling);

                    // Check if the window is lesser than the minimum size
                    if (window.Width < minSize.Width || window.Height < minSize.Height)
                    {
                        // If we are searching in greater to smaller mode,
                        if (scalingMode == ObjectDetectorScalingMode.GreaterToSmaller)
                        {
                            break; // it won't get bigger, so we should stop.
                        }
                        else continue; // continue until it gets greater.
                    }

                    // Check if the window is greater than the maximum size
                    else if (window.Width > maxSize.Width || window.Height > maxSize.Height)
                    {
                        // If we are searching in greater to smaller mode,
                        if (scalingMode == ObjectDetectorScalingMode.GreaterToSmaller)
                        {
                            continue; // continue until it gets smaller.
                        }

                        break; // it won't get smaller, so we should stop. 
                    }

                    // Grab some scan loop parameters
                    int xStep = window.Width >> 3;
                    int yStep = window.Height >> 3;

                    int xEnd = width - window.Width;
                    int yEnd = height - window.Height;


                    // Parallel mode. Scan the integral image searching
                    // for objects in the window with parallelization.
                    var bag = new System.Collections.Concurrent.ConcurrentBag<Rectangle>();

                    int numSteps = (int)Math.Ceiling((double)yEnd / yStep);

                    // For each pixel in the window column
                    var window1 = window;
                    Parallel.For(
                        0,
                        numSteps,
                        (j, options) =>
                        {
                            int y = j * yStep;

                            // Create a local window reference
                            Rectangle localWindow = window1;

//.........这里部分代码省略.........
开发者ID:AlexSkarbo,项目名称:ImageProcessor,代码行数:101,代码来源:HaarObjectDetector.cs


示例18: Trace

        /// <summary>
        /// Traces the edges of a given <see cref="Image"/>.
        /// </summary>
        /// <param name="source">
        /// The source <see cref="Image"/>.
        /// </param>
        /// <param name="destination">
        /// The destination <see cref="Image"/>.
        /// </param>
        /// <param name="threshold">
        /// The threshold (between 0 and 255).
        /// </param>
        /// <returns>
        /// The a new instance of <see cref="Bitmap"/> traced.
        /// </returns>
        public static Bitmap Trace(Image source, Image destination, byte threshold = 0)
        {
            int width = source.Width;
            int height = source.Height;

            // Grab the edges converting to greyscale, and invert the colors.
            ConvolutionFilter filter = new ConvolutionFilter(new SobelEdgeFilter(), true);

            using (Bitmap temp = filter.Process2DFilter(source))
            {
                destination = new InvertMatrixFilter().TransformImage(temp, destination);

                // Darken it slightly to aid detection
                destination = Adjustments.Brightness(destination, -5);
            }

            // Loop through and replace any colors more white than the threshold
            // with a transparent one.
            using (FastBitmap destinationBitmap = new FastBitmap(destination))
            {
                Parallel.For(
                    0,
                    height,
                    y =>
                    {
                        for (int x = 0; x < width; x++)
                        {
                            // ReSharper disable AccessToDisposedClosure
                            Color color = destinationBitmap.GetPixel(x, y);
                            if (color.B >= threshold)
                            {
                                destinationBitmap.SetPixel(x, y, Color.Transparent);
                            }
                            // ReSharper restore AccessToDisposedClosure
                        }
                    });
            }

            // Darken it again to average out the color.
            destination = Adjustments.Brightness(destination, -5);

            return (Bitmap)destination;
        }
开发者ID:ChaseFlorell,项目名称:ImageProcessor,代码行数:58,代码来源:Effects.cs


示例19: SetAtlas

 public void SetAtlas( Bitmap bmp )
 {
     Dispose();
     this.bmp = bmp;
     fastBmp = new FastBitmap( bmp, true );
 }
开发者ID:umby24,项目名称:ClassicalSharp,代码行数:6,代码来源:Animations.cs


示例20: ApplyFilter

        /// <summary>
        /// Applies the oil painting filter. 
        /// </summary>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <returns>
        /// The <see cref="Bitmap"/>.
        /// </returns>
        public Bitmap ApplyFilter(Bitmap source)
        {
            // TODO: Make this class implement an interface?
            int width = source.Width;
            int height = source.Height;

            int radius = this.brushSize >> 1;

            Bitmap destination = new Bitmap(width, height, PixelFormat.Format32bppPArgb);
            destination.SetResolution(source.HorizontalResolution, source.VerticalResolution);
            using (FastBitmap sourceBitmap = new FastBitmap(source))
            {
                using (FastBitmap destinationBitmap = new FastBitmap(destination))
                {
                    Parallel.For(
                        0,
                        height,
                        y =>
                        {
                            for (int x = 0; x < width; x++)
                            {
                                int maxIntensity = 0;
                                int maxIndex = 0;
                                int[] intensityBin = new int[this.levels];
                                int[] blueBin = new int[this.levels];
                                int[] greenBin = new int[this.levels];
                                int[] redBin = new int[this.levels];
                                byte sourceAlpha = 255;

                                for (int i = 0; i <= radius; i++)
                                {
                                    int ir = i - radius;
                                    int offsetY = y + ir;

                                    // Skip the current row
                                    if (offsetY < 0)
                                    {
                                        continue;
                                    }

                                    // Outwith the current bounds so break.
                                    if (offsetY >= height)
                                    {
                                        break;
                                    }

                                    for (int fx = 0; fx <= radius; fx++)
                                    {
                                        int jr = fx - radius;
                                        int offsetX = x + jr;

                                        // Skip the column
                                        if (offsetX < 0)
                                        {
                                            continue;
                                        }

                                        if (offsetX < width)
                                        {
                                            // ReSharper disable once AccessToDisposedClosure
                                            Color color = sourceBitmap.GetPixel(offsetX, offsetY);

                                            byte sourceBlue = color.B;
                                            byte sourceGreen = color.G;
                                            byte sourceRed = color.R;
                                            sourceAlpha = color.A;

                                            int currentIntensity = (int)Math.Round(((sourceBlue + sourceGreen + sourceRed) / 3.0 * (this.levels - 1)) / 255.0);

                                            intensityBin[currentIntensity] += 1;
                                            blueBin[currentIntensity] += sourceBlue;
                                            greenBin[currentIntensity] += sourceGreen;
                                            redBin[currentIntensity] += sourceRed;

                                            if (intensityBin[currentIntensity] > maxIntensity)
                                            {
                                                maxIntensity = intensityBin[currentIntensity];
                                                maxIndex = currentIntensity;
                                            }
                                        }
                                    }
                                }

                                byte blue = Math.Abs(blueBin[maxIndex] / maxIntensity).ToByte();
                                byte green = Math.Abs(greenBin[maxIndex] / maxIntensity).ToByte();
                                byte red = Math.Abs(redBin[maxIndex] / maxIntensity).ToByte();

                                // ReSharper disable once AccessToDisposedClosure
                                destinationBitmap.SetPixel(x, y, Color.FromArgb(sourceAlpha, red, green, blue));
                            }
                        });
//.........这里部分代码省略.........
开发者ID:CastleSoft,项目名称:ImageProcessor,代码行数:101,代码来源:OilPaintingFilter.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Drawing.Font类代码示例发布时间:2022-05-26
下一篇:
C# Drawing.ColorConverter类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap