winRT 图片验证码生成
来源:互联网 发布:湖南青果软件 好不好 编辑:程序博客网 时间:2024/05/22 00:32
今天纠结了半天这个问题,windows phone 采用下面方法进行画图,原理很简单,主要是先创建一个Grid当画板,在其上面添加各种控件,组成一个类似验证码的图形,然后再转成图片格式,在UI层绑定Iamge 控件。
public void CreatImage(string Text, Image imgsource, int iw, int ih) { Grid Gx = new Grid(); Canvas cv1 = new Canvas(); for (int i = 0; i < 6; i++) { Polyline p = new Polyline(); for (int ix = 0; ix < r.Next(3, 6); ix++) { p.Points.Add(new Point(r.NextDouble() * iw, r.NextDouble() * ih)); } byte[] Buffer = new byte[3]; r.NextBytes(Buffer); SolidColorBrush SC = new SolidColorBrush(Color.FromArgb(255, Buffer[0], Buffer[1], Buffer[2])); p.Stroke = SC; p.StrokeThickness = 0.5; cv1.Children.Add(p); } Canvas cv2 = new Canvas(); int y = 0; int lw = 6; double w = (iw - lw) / Text.Length; int h = (int)ih; foreach (char x in Text) { byte[] Buffer = new byte[3]; r.NextBytes(Buffer); SolidColorBrush SC = new SolidColorBrush(Color.FromArgb(255, Buffer[0], Buffer[1], Buffer[2])); TextBlock t = new TextBlock(); t.TextAlignment = TextAlignment.Center; t.FontSize = 40;//r.Next(h - 3, h); t.FontWeight = FontWeights.Bold; t.Foreground = SC; t.Text = x.ToString(); t.Projection = new PlaneProjection() { RotationX = r.Next(-30, 30), RotationY = r.Next(-30, 30), RotationZ = r.Next(-10, 10) }; cv2.Children.Add(t); Canvas.SetLeft(t, lw / 2 + y * w); Canvas.SetTop(t, 0); y++; } Gx.Children.Add(cv1); Gx.Children.Add(cv2); WriteableBitmap W = new WriteableBitmap(Gx, new TransformGroup()); W.Render(Gx, new TransformGroup()); imgsource.Source = W; }
但是发现RT上WriteableBitmap类已经没有下面的构造函数
public WriteableBitmap(UIElement element, Transform transform);
也就是说上面的Grid已经找不到方法转成图片。我寻找了三方画图控件库(http://writeablebitmapex.codeplex.com/),发现也不支持画文字、数字。
正在纠结时,换个角度柳暗花明啊。
客户端为何不用图片,直接绑定Grid
UI层用:
<ContentControl HorizontalAlignment="Left" Width="120" Height="50" Content="{Binding CheckCodeImage,Mode=TwoWay}" ></ContentControl>
希望对你有用!
<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- winRT 图片验证码生成
- 验证码图片生成
- 生成图片验证码
- 生成验证码图片
- 生成验证码图片
- 生成验证码图片
- 生成验证码图片
- 生成验证码图片
- 生成图片验证码
- 生成图片验证码
- 生成验证码图片
- 图片验证码生成
- 生成图片验证码
- 生成图片验证码
- 生成验证码图片
- 验证码图片生成
- 生成验证码图片
- 生成图片验证码
- struct关键字---C语言深度剖析读书笔记9
- POJ 1236 Network of Schools
- Kinect SDK1.7 迎来重大更新
- (代码4)简单视频控制
- C#对EXCEL文件操作
- winRT 图片验证码生成
- Apache Common fileUpload API 详解
- js---js的concat函数、join 、slice函数及二维数组的定义方式
- Android关于OnTouch 和OnClick同时调用冲突的解决方案
- UML类图
- 一个简单的哈希表的实现
- ajax 在debug和alert时都正确但是直接运行却报错
- Apache POI组件读取Excel文档内存溢出
- JSP页面无故报错 javax.servlet.jsp.PageContext cannot be resolved to a type