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


C# UnmanagedImage.Clone方法代码示例

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


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

示例1: ProcessFilter

        /// <summary>
        /// Process the filter on the specified image.
        /// </summary>
        /// 
        /// <param name="image">Source image data.</param>
        ///
        protected override unsafe void ProcessFilter( UnmanagedImage image )
        {
            // copy source image
            UnmanagedImage sourceImage = image.Clone( );
            // perform closing on the source image
            closing.ApplyInPlace( image );
            // subtract source image from the closed image
            subtract.UnmanagedOverlayImage = sourceImage;
            subtract.ApplyInPlace( image );

            sourceImage.Dispose( );
        }
开发者ID:EnergonV,项目名称:BestCS,代码行数:18,代码来源:BottomHat.cs

示例2: Apply

        /// <summary>
        /// Perform color dithering for the specified image.
        /// </summary>
        /// 
        /// <param name="sourceImage">Source image to do color dithering for.</param>
        /// 
        /// <returns>Returns color dithered image. See <see cref="ColorTable"/> for information about format of
        /// the result image.</returns>
        /// 
        /// <exception cref="UnsupportedImageFormatException">Unsupported pixel format of the source image. It must 24 or 32 bpp color image.</exception>
        /// 
        public Bitmap Apply( UnmanagedImage sourceImage )
        {
            if ( ( sourceImage.PixelFormat != PixelFormat.Format24bppRgb ) &&
                 ( sourceImage.PixelFormat != PixelFormat.Format32bppRgb ) &&
                 ( sourceImage.PixelFormat != PixelFormat.Format32bppArgb ) &&
                 ( sourceImage.PixelFormat != PixelFormat.Format32bppPArgb ) )
            {
                throw new UnsupportedImageFormatException( "Unsupported pixel format of the source image." );
            }

            cache.Clear( );

            // make a copy of the original image
            UnmanagedImage source = sourceImage.Clone( );

            // get image size
            width  = sourceImage.Width;
            height = sourceImage.Height;
            stride = sourceImage.Stride;
            pixelSize = Bitmap.GetPixelFormatSize( sourceImage.PixelFormat ) / 8;

            int offset = stride - width * pixelSize;

            // create destination image
            Bitmap destImage = new Bitmap( width, height, ( colorTable.Length > 16 ) ?
                PixelFormat.Format8bppIndexed : PixelFormat.Format4bppIndexed );
            // and init its palette
            ColorPalette cp = destImage.Palette;
            for ( int i = 0, n = colorTable.Length; i < n; i++ )
            {
                cp.Entries[i] = colorTable[i];
            }
            destImage.Palette = cp;

            // lock destination image
            BitmapData destData = destImage.LockBits( new Rectangle( 0, 0, width, height ),
                ImageLockMode.ReadWrite, destImage.PixelFormat );

            // pixel values
            int r, g, b;

            // do the job
            unsafe
            {
                byte* ptr = (byte*) source.ImageData.ToPointer( );
                byte* dstBase = (byte*) destData.Scan0.ToPointer( );
                byte colorIndex;

                bool is8bpp = ( colorTable.Length > 16 );

                // for each line
                for ( y = 0; y < height; y++ )
                {
                    byte* dst = dstBase + y * destData.Stride;

                    // for each pixels
                    for ( x = 0; x < width; x++, ptr += pixelSize )
                    {
                        r = ptr[RGB.R];
                        g = ptr[RGB.G];
                        b = ptr[RGB.B];

                        // get color from palette, which is the closest to current pixel's value
                        Color closestColor = GetClosestColor( r, g, b, out colorIndex );

                        // do error diffusion
                        Diffuse( r - closestColor.R, g - closestColor.G, b - closestColor.B, ptr );

                        // write color index as pixel's value to destination image
                        if ( is8bpp )
                        {
                            *dst = colorIndex;
                            dst++;
                        }
                        else
                        {
                            if ( x % 2 == 0 )
                            {
                                *dst |= (byte) ( colorIndex << 4 );
                            }
                            else
                            {
                                *dst |= ( colorIndex );
                                dst++;
                            }
                        }
                    }
                    ptr += offset;
                }
//.........这里部分代码省略.........
开发者ID:accord-net,项目名称:framework,代码行数:101,代码来源:ErrorDiffusionColorDithering.cs


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