我已经考虑使用一些预定义的网格和点映射系统来转换我自己的方法来转换点.但是,似乎有一些算法或样本如何做到这一点已经可用?
解决方法 以下是我们使用的验证码生成器中的几种方法,它们可能会引导您朝着正确的方向前进:internal static voID DrawPhrase( this Graphics graphics,int wIDth,int height,string phrase) { graphics.FillRectangle( Brushes.White,wIDth,height); using (var gp = new GraphicsPath()) { gp.AddString(phrase,FontFamily.GenericMonospace,(int)FontStyle.Bold,33f,new Point(0,0),StringFormat.GenericTypographic); using (var gpp = gp.Deform(wIDth,height)) { var bounds = gpp.GetBounds(); var matrix = new Matrix(); var x = (wIDth - bounds.WIDth) / 2 - bounds.left; var y = (height - bounds.Height) / 2 - bounds.top; matrix.Translate(x,y); gpp.transform(matrix); graphics.FillPath(Brushes.Black,gpp); } } graphics.Flush(); } internal static GraphicsPath Deform( this GraphicsPath path,int height) { var WarpFactor = 4; var xAmp = WarpFactor * wIDth / 300d; var yAmp = WarpFactor * height / 50d; var xFreq = 2d * Math.PI / wIDth; var yFreq = 2d * Math.PI / height; var deformed = new PointF[path.PathPoints.Length]; var xSeed = rng.NextDouble() * 2 * Math.PI; var ySeed = rng.NextDouble() * 2 * Math.PI; var i = 0; foreach (var original in path.PathPoints) { var val = xFreq * original.X + yFreq * original.Y; var xOffset = (int)(xAmp * Math.Sin(val + xSeed)); var yOffset = (int)(yAmp * Math.Sin(val + ySeed)); deformed[i++] = new PointF(original.X + xOffset,original.Y + yOffset); } return new GraphicsPath(deformed,path.PathTypes); }总结
以上是内存溢出为你收集整理的c# – .Net Graphicspath的包络失真全部内容,希望文章能够帮你解决c# – .Net Graphicspath的包络失真所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)