本文整理汇总了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;
}
示例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;
}
示例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
}
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例8: GetParent
public static XPathNavigator GetParent(this XPathNavigator navigator)
{
navigator = navigator.Clone();
if (!navigator.MoveToParent())
throw Error.InvalidOperation();
return navigator;
}
示例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;
}
示例10: AlignTopRight
public static Style AlignTopRight(this Style style)
{
return style
.Clone ()
.Set (Label.YAlignProperty, TextAlignment.Start)
.Set (Label.XAlignProperty, TextAlignment.End);
}
示例11: AlignCenterLeft
public static Style AlignCenterLeft(this Style style)
{
return style
.Clone ()
.Set (Label.YAlignProperty, TextAlignment.Center)
.Set (Label.XAlignProperty, TextAlignment.Start);
}
示例12: AlignBottomLeft
public static Style AlignBottomLeft(this Style style)
{
return style
.Clone ()
.Set (Label.YAlignProperty, TextAlignment.End)
.Set (Label.XAlignProperty, TextAlignment.Start);
}
示例13: AlignBottomCenter
public static Style AlignBottomCenter(this Style style)
{
return style
.Clone ()
.Set (Label.YAlignProperty, TextAlignment.End)
.Set (Label.XAlignProperty, TextAlignment.Center);
}
示例14: CloneWithMessageId
public static BrokeredMessage CloneWithMessageId(this BrokeredMessage toSend)
{
var clone = toSend.Clone();
clone.MessageId = toSend.MessageId;
toSend = clone;
return toSend;
}
示例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;
}