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


C# this.Clone方法代码示例

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


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

示例1: ZadehMaxMinImplication

        /// <summary>
        /// Zadeh Max Min Implication Operator
        /// </summary>
        /// <param name="elementA">FuzzyElement A</param>
        /// <param name="elementB">FuzzyElement B</param>
        /// <returns>FuzzyElement</returns>
        public static IFuzzyElement ZadehMaxMinImplication(this IFuzzyElement elementA, IFuzzyElement elementB)
        {
            var fuzzy = elementA.Clone();
            fuzzy.Value = elementA.Min(elementB).Max(elementA.Clone(x => x.Value = 1 - elementA.Value)).Value;

            return fuzzy;
        }
开发者ID:rpalaniappan,项目名称:FuzzySharp,代码行数:13,代码来源:Implications.cs

示例2: GetPossibleStates

        public static List<NimState> GetPossibleStates(this NimState state)
        {
            List<NimState> states = new List<NimState>();

            for (int i = 1; i <= state.XReal; i++) {

                NimState tempState = state.Clone();
                tempState.XReal -= i;
                if (tempState.HasValidMoves())
                    states.Add(tempState);
            }

            for (int i = 1; i <= state.YReal; i++) {

                NimState tempState = state.Clone();
                tempState.YReal -= i;
                if (tempState.HasValidMoves())
                    states.Add(tempState);
            }

            for (int i = 1; i <= state.ZReal; i++) {

                NimState tempState = state.Clone();
                tempState.ZReal -= i;
                if (tempState.HasValidMoves())
                    states.Add(tempState);
            }

            return states;
        }
开发者ID:jonje,项目名称:NimGame,代码行数:30,代码来源:NimStateHelper.cs

示例3: CropWhitespace

        public static Bitmap CropWhitespace(this Bitmap bmp)
        {
            int bitPerPixel = Image.GetPixelFormatSize(bmp.PixelFormat);

            if(bitPerPixel != 24 && bitPerPixel != 32)
                throw new InvalidOperationException($"Invalid PixelFormat: {bitPerPixel}b");

            var bottom = 0;
            var left = bmp.Width;
            var right = 0;
            var top = bmp.Height;

            BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, bmp.PixelFormat);
            unsafe
            {
                byte* dataPtr = (byte*)bmpData.Scan0;

                for(var y = 0; y < bmp.Height; y++) {
                    for(var x = 0; x < bmp.Width; x++) {
                        var rgbPtr = dataPtr + (x * (bitPerPixel / 8));

                        var b = rgbPtr[0];
                        var g = rgbPtr[1];
                        var r = rgbPtr[2];

                        byte? a = null;
                        if(bitPerPixel == 32) {
                            a = rgbPtr[3];
                        }

                        if(b != 0xFF || g != 0xFF || r != 0xFF || (a.HasValue && a.Value != 0xFF)) {
                            if(x < left)
                                left = x;

                            if(x >= right)
                                right = x + 1;

                            if(y < top)
                                top = y;

                            if(y >= bottom)
                                bottom = y + 1;
                        }
                    }

                    dataPtr += bmpData.Stride;
                }
            }
            bmp.UnlockBits(bmpData);

            if(left < right && top < bottom) {
                var width = right - left;
                var height = bottom - top;

                var croppedImg = bmp.Clone(new Rectangle(left, top, width, height), bmp.PixelFormat);
                return croppedImg;
            } else {
                return bmp; // Entire image should be cropped, it is empty
            }
        }
开发者ID:GWigWam,项目名称:NeuralNet,代码行数:60,代码来源:ImageEdit.cs

示例4: LUDecomposition

        /// <summary>
        /// 行列の LU 分解をおこないます。
        /// 対角要素を除く下三角の要素が行列 L (対角要素はすべて 1), 上三角の要素が行列 U を表す行列を返します。
        /// </summary>
        /// <param name="A">対象とする行列</param>
        /// <returns>対角要素を除く下三角の要素が行列 L (対角要素はすべて 1), 上三角の要素が行列 U を表す行列を返します。</returns>
        public static Matrix LUDecomposition(this Matrix A)
        {
            if ((A.Rows == 0) || (A.Columns == 0) || (A.Rows != A.Columns))
                throw new Exception("LU 分解できません。");

            var mat = A.Clone();
            var n = mat.Rows;

            for (int k = 0; k < n; k++)
            {
                var temp = 1.0 / mat[k, k];
                for (int i = k + 1; i < n; i++)
                {
                    mat[i, k] = mat[i, k] * temp;
                }

                for (int j = k + 1; j < n; j++)
                {
                    var Akj = mat[k, j];
                    for (int i = k + 1; i < n; i++)
                    {
                        mat[i, j] -= mat[i, k] * Akj;
                    }
                }
            }

            return mat;
        }
开发者ID:YKSoftware,项目名称:YKToolkit.Controls,代码行数:34,代码来源:YKMath.cs

示例5: Correlation

 public static Bitmap Correlation(this Bitmap input, byte[,] mask, int maskWidth, int maskHeight)
 {
     Bitmap clone = input.Clone() as Bitmap;
     int total = 0;
     int a = (maskWidth - 1) >> 1;
     int b = (maskHeight - 1) >> 1;
     for(int x = 0; x < input.Width; x++)
     {
         for(int y = 0; y < input.Height; y++)
         {
             for(int s = 0, _s = -a; s < maskWidth; s++, _s++)
             {
                 int wX = x + _s;
                 if(wX < 0 || wX >= input.Width)
                     continue;
                 for(int t = 0, _t = -b; t < maskHeight; t++, _t++)
                 {
                     int wY = y + _t;
                     if(wY < 0 || wY >= input.Height)
                         continue;
                     int w = mask[s, t];
                     int f = input.GetPixel(wX, wY).R;
                     total += (w * f);
                 }
             }
             byte value = (byte)total;
             clone.SetPixel(x,y, Color.FromArgb(255, value, value, value));
             total = 0;
         }
     }
     return clone;
 }
开发者ID:DrItanium,项目名称:Imaging,代码行数:32,代码来源:SpatialFilteringExtensions.cs

示例6: Resize

        /// <summary>
        /// Resizes the specified image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="size">The size.</param>
        /// <returns></returns>
        public static Image Resize(this Image image, Size size)
        {
            Size newSize = new Size(size.Width, size.Height);

            if (image.Size.Width > image.Size.Height)
            {
                newSize.Height = (image.Size.Height * size.Width) / image.Size.Width;
            }
            else
            {
                newSize.Width = (image.Size.Width * size.Height) / image.Size.Height;
            }

            Rectangle   rectangle   = new Rectangle(0, 0, newSize.Width, newSize.Height);
            Image       resized     = new Bitmap(newSize.Width, newSize.Height, image.PixelFormat);

            using (Graphics graphic = Graphics.FromImage(resized))
            {
                graphic.CompositingQuality  = CompositingQuality.HighQuality;
                graphic.SmoothingMode       = SmoothingMode.HighQuality;
                graphic.InterpolationMode   = InterpolationMode.HighQualityBicubic;

                graphic.DrawImage((System.Drawing.Image)image.Clone(), rectangle);
            }

            return resized;
        }
开发者ID:cipjota,项目名称:Chronos,代码行数:33,代码来源:ImageExtensions.cs

示例7: GetInnerXml

        /// <summary>
        /// This is used to get the inner XML of a node without changing the spacing
        /// </summary>
        /// <param name="node">The node from which to get the inner XML</param>
        /// <returns>The inner XML as a string with its spacing preserved</returns>
        /// <exception cref="ArgumentNullException">This is thrown if the <paramref name="node"/> parameter
        /// is null.</exception>
        public static string GetInnerXml(this XPathNavigator node)
        {
            if(node == null)
                throw new ArgumentNullException("node");

            // Clone the node so that we don't change the input
            XPathNavigator current = node.Clone();

            XmlWriterSettings settings = new XmlWriterSettings();
            settings.ConformanceLevel = ConformanceLevel.Fragment;
            settings.OmitXmlDeclaration = true;

            StringBuilder builder = new StringBuilder();

            using(XmlWriter writer = XmlWriter.Create(builder, settings))
            {
                // write the output
                bool writing = current.MoveToFirstChild();

                while(writing)
                {
                    current.WriteSubtree(writer);
                    writing = current.MoveToNext();
                }
            }

            return builder.ToString();
        }
开发者ID:julianhaslinger,项目名称:SHFB,代码行数:35,代码来源:BuildComponentUtilities.cs

示例8: GetParent

		public static XPathNavigator GetParent(this XPathNavigator navigator)
		{
			navigator = navigator.Clone();
			if (!navigator.MoveToParent())
				throw Error.InvalidOperation();
			return navigator;
		}
开发者ID:elevine,项目名称:Core,代码行数:7,代码来源:XPathExtensions.cs

示例9: RGBToBGR

        internal static Image RGBToBGR(this Image bmp)
        {
            Image newBmp;
            if ((bmp.PixelFormat & Imaging.PixelFormat.Indexed) != 0)
            {
                newBmp = new Bitmap(bmp.Width, bmp.Height, Imaging.PixelFormat.Format32bppArgb);
            }
            else
            {
                // Need to clone so the call to Clear() below doesn't clear the source before trying to draw it to the target.
                newBmp = (Image)bmp.Clone();
            }

            try
            {
                System.Drawing.Imaging.ImageAttributes ia = new System.Drawing.Imaging.ImageAttributes();
                System.Drawing.Imaging.ColorMatrix cm = new System.Drawing.Imaging.ColorMatrix(rgbtobgr);

                ia.SetColorMatrix(cm);
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newBmp))
                {
                    g.Clear(Color.Transparent);
                    g.DrawImage(bmp, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, System.Drawing.GraphicsUnit.Pixel, ia);
                }
            }
            finally
            {
                if (newBmp != bmp)
                {
                    bmp.Dispose();
                }
            }

            return newBmp;
        }
开发者ID:Zodge,项目名称:MonoGame,代码行数:35,代码来源:ImageEx.cs

示例10: AlignTopRight

 public static Style AlignTopRight(this Style style)
 {
     return style
             .Clone ()
             .Set (Label.YAlignProperty, TextAlignment.Start)
             .Set (Label.XAlignProperty, TextAlignment.End);
 }
开发者ID:jv9,项目名称:Fluent-Xamarin-Forms,代码行数:7,代码来源:LabelAlignmentExtensions.cs

示例11: AlignCenterLeft

 public static Style AlignCenterLeft(this Style style)
 {
     return style
             .Clone ()
             .Set (Label.YAlignProperty, TextAlignment.Center)
             .Set (Label.XAlignProperty, TextAlignment.Start);
 }
开发者ID:jv9,项目名称:Fluent-Xamarin-Forms,代码行数:7,代码来源:LabelAlignmentExtensions.cs

示例12: AlignBottomLeft

 public static Style AlignBottomLeft(this Style style)
 {
     return style
             .Clone ()
             .Set (Label.YAlignProperty, TextAlignment.End)
             .Set (Label.XAlignProperty, TextAlignment.Start);
 }
开发者ID:jv9,项目名称:Fluent-Xamarin-Forms,代码行数:7,代码来源:LabelAlignmentExtensions.cs

示例13: AlignBottomCenter

 public static Style AlignBottomCenter(this Style style)
 {
     return style
             .Clone ()
             .Set (Label.YAlignProperty, TextAlignment.End)
             .Set (Label.XAlignProperty, TextAlignment.Center);
 }
开发者ID:jv9,项目名称:Fluent-Xamarin-Forms,代码行数:7,代码来源:LabelAlignmentExtensions.cs

示例14: CloneWithMessageId

 public static BrokeredMessage CloneWithMessageId(this BrokeredMessage toSend)
 {
     var clone = toSend.Clone();
     clone.MessageId = toSend.MessageId;
     toSend = clone;
     return toSend;
 }
开发者ID:danielmarbach,项目名称:NServiceBus.AzureServiceBus,代码行数:7,代码来源:BrokeredMessageExtensions.cs

示例15: WhereAll

 /// <summary>
 /// REplaces the current where clause with the passed clause
 /// </summary>
 /// <param name="queryBuilder"></param>
 /// <param name="where"></param>
 /// <returns></returns>
 public static IQueryBuilder WhereAll(this IQueryBuilder queryBuilder, IWhere where)
 {
     var qb = queryBuilder.Clone();
     qb.QueryDef.Where.Clear();
     qb.QueryDef.Where.Add(where);
     return qb;
 }
开发者ID:saneman1,项目名称:IQMap,代码行数:13,代码来源:SqlQueryMaker.cs


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