论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Flash AS编程教程
Tag:2.0,3.0菜鸟,游戏,,cs,技巧,源码,,文本,文字,函数,音乐,随机,拖拽,asp,access,xml,mc,视频教程

asp.net与flash结合来实现painting后再上传图片

文章类别:Flash AS编程 | 发表日期:2008-10-6 17:34:58


我想实现在web page里用mouse签名,后把这张签名图保存到DB, 搜过一些解决方案,代码给得好散, 我就来实现一个完整的, 还可以扩展, 代码如下:

Action Script:

1. var photow=100;//绘图区宽度
2.
3. var photoh=100;//绘图区高
4.
5.
6.
7. //photoPreview3._width=photow;
8.
9. //photoPreview3._height=photoh;
10.
11.
12.
13. //photow = new Number(150);
14.
15. //photoh = new Number(150);
16.
17. //var bitmap:ByteArray=new ByteArray();//记录当前绘图
18.
19. var bitmap:Array=new Array();//记录当前绘图
20.
21. for(i=0;i<photoh*photow;i++)
22.
23. {
24.
25. bitmap[i]=255;
26.
27. }
28.
29.
30.
31. _root.onMouseDown = function()
32.
33. {
34.
35. _root.lineStyle(2, 0xFF0000, 100);
36.
37. _root.moveTo(_root._xmouse, _root._ymouse);
38.
39. isDrawing = true;
40.
41. };
42.
43.
44.
45. _root.onMouseMove = function()
46.
47. {
48.
49. if (isDrawing == true)
50.
51. {
52.
53. _root.lineTo(_root._xmouse, _root._ymouse);
54.
55. updateAfterEvent();
56.
57. }
58.
59. };
60.
61.
62.
63. _root.onMouseUp = function()
64.
65. {
66.
67. isDrawing = false;
68.
69. };
70.
71.
72.
73. Clear_btn.onRelease = function()
74.
75. {
76.
77. _root.clear();
78.
79. //photoPreview3.clear();
80.
81. };
82.
83.
84.
85. //该对象用于实现发送数据到网页可get或post
86.
87. var lv:LoadVars;
88.
89. lv = new LoadVars();
90.
91.
92.
93. Preview_btn.onRelease = function()
94.
95. {
96.
97. //新建一个bitmapdate对象并获取video上的图像信息
98.
99. lv.bm = new flash.display.BitmapData(photow, photoh,true, 0);
100.
101. lv.bm.draw(_root);
102.
103. //lv.bm.draw(photoPreview3);
104.
105. //photoPreview是在场景中的一个Movie clip实例,用于输出bitmapdate实现照片预缆
106.
107. photoPreview2.attachBitmap(lv.bm, 1);
108.
109. photoPreview2._width=photow;
110.
111. photoPreview2._height=photoh;
112.
113. trace(lv.bm.height);
114.
115. trace(lv.bm.width);
116.
117. //getURL("http://www.macromedia.com", "_blank", "GET");
118.
119. };
120.
121. Save_btn.onRelease = function()
122.
123. {
124.
125. savePic();
126.
127. //getURL("http://localhost/CaptureAndSignatureWebApp/pageb.aspx", "_blank", "GET");
128.
129. };
130.
131.
132.
133. function savePic()
134.
135. {
136.
137. //loading._visible =true;
138.
139. //getURL("http://localhost/CaptureAndSignatureWebApp/pageb.aspx?aa=aabb", "_blank", "GET");
140.
141.
142.
143. //读取图片矩形范围的像素信息,并以字符串的形式连接起来 begin
144.
145. //i = lv.bm.height;
146.
147. i = photoh;
148.
149. trace("i: " + i.toString());
150.
151. //j = lv.bm.width;
152.
153. j = photow;
154.
155. trace("j: " + j.toString());
156.
157. //trace("a: " + i.toString());
158.
159. //trace("b: " + j.toString());
160.
161. rgb_array = "";
162.
163. for (var m = i - 1; m >= 0; m--)
164.
165. //for (y = 10 - 1; y >= 0; y--)
166.
167. {
168.
169. trace(rgb_array);
170.
171. for (var n = 0; n < j; n ++)
172.
173. //for (x = 0; x < 10; x++)
174.
175. {
176.
177. trace("m: " + m.toString());
178.
179. trace("n: " + n.toString());
180.
181. color = lv.bm.getPixel(n, m).toString(16);
182.
183. if(color == "0")
184.
185. {
186.
187. color = "FFFFFF";
188.
189. }
190.
191. trace(color);
192.
193. trace(rgb_array);
194.
195. rgb_array = rgb_array + (color + ",");
196.
197. } // end of for
198.
199.
200.
201. //trace(rgb_array);
202.
203. } // end of for
204.
205. lv.height = i;
206.
207. lv.width = j;
208.
209. lv.rgb_array = rgb_array;
210.
211. //camera_lbl.text = rgb_array;
212.
213. getURL("http://localhost/CaptureAndSignatureWebApp/pageC.aspx?passVal=1", "_blank", "POST");
214.
215. //读取图片矩形范围的像素信息,并以字符串的形式连接起来 end
216.
217.
218.
219. //getURL("javascript:alert('Step_1')");
220.
221. //发送到要处理的页面URL,可以在页面通过Request.Form["名称"]获取值,如:Request.Form["rgb_array"]
222.
223. //lv.sendAndLoad("http://localhost/CaptureAndSignatureWebApp/pageb.aspx", lv, "POST");
224.
225.
226.
227. //当页面返回信息即页面处理完成后,触发的行为
228.
229. /*
230.
231. lv.onLoad = function (success)
232.
233. {
234.
235. if (success)
236.
237. {
238.
239. //跳转到其他页面
240.
241. getURL("http://localhost/CaptureAndSignatureWebApp/pageb.aspx", "_self");
242.
243. }
244.
245. else
246.
247. {
248.
249. getURL("javascript:alert('Not Success')");
250.
251. }
252.
253. }
254.
255. */
256.
257. }
258.
259.
260.
261. /*
262.
263. photoPreview3.onMouseDown = function()
264.
265. {
266.
267. photoPreview3.lineStyle(5, 0xFF0000, 100);
268.
269. photoPreview3.moveTo(photoPreview3._xmouse, photoPreview3._ymouse);
270.
271. isDrawing = true;
272.
273. };
274.
275.
276.
277. photoPreview3.onMouseMove = function()
278.
279. {
280.
281. if (isDrawing == true)
282.
283. {
284.
285. photoPreview3.lineTo(photoPreview3._xmouse, photoPreview3._ymouse);
286.
287. updateAfterEvent();
288.
289. }
290.
291. };
292.
293.
294.
295. photoPreview3.onMouseUp = function()
296.
297. {
298.
299. isDrawing = false;
300.
301. };
302.
303. */




ASP.NET代码如下

1. <pre class="csharp" name="code">using System;
2.
3. using System.Data;
4.
5. using System.Configuration;
6.
7. using System.Collections;
8.
9. using System.Web;
10.
11. using System.Web.Security;
12.
13. using System.Web.UI;
14.
15. using System.Web.UI.WebControls;
16.
17. using System.Web.UI.WebControls.WebParts;
18.
19. using System.Web.UI.HtmlControls;
20.
21.
22.
23. namespace CaptureAndSignatureWebApp
24.
25. {
26.
27. public partial class pageC : System.Web.UI.Page
28.
29. {
30.
31. protected void Page_Load(object sender, EventArgs e)
32.
33. {
34.
35. //string[] rgbArray = new string[] { Request.Form["rgb_array"] };
36.
37. //this.DrawImageFromFlashUploader(240, 140, rgbArray).Save("images/1.bmp");
38.
39. //this.Image1.ImageUrl = "images/1.bmp";
40.
41.
42.
43. }
44.
45.
46.
47. protected override void OnPreInit(EventArgs e)
48.
49. {
50.
51. base.OnPreInit(e);
52.
53.
54.
55. string ss = "";
56.
57. if (Request.Form.Count > 0)
58.
59. {
60.
61. //ss = Request.QueryString["passVal"];
62.
63. ss = Request.Form["rgb_array"];
64.
65. this.Label1.Text = ss;
66.
67.
68.
69. string[] rgbArray = ss.Split(new char[] { ',' });
70.
71. this.DrawImageFromFlashUploader(100, 100, rgbArray).Save(@"E:\Work \ODMS\SCAAS\技术难点\CaptureAndSignatureWebApp\CaptureAndSignatureWebApp \images\1.bmp");
72.
//this.Image1.ImageUrl = @"~E:\Work\ODMS\SCAAS\技术难点\CaptureAndSignatureWebApp\CaptureAndSignatureWebApp\images\1.bmp";
73.
74. this.IMG1.Src = @"images/1.bmp";
75.
76.
77.
78. //Response.ContentType = "image/gif";
79.
80. //MemoryStream str = new MemoryStream();
81.
82. ////System.Drawing.Imaging.ImageFormat iFormat = new System.Drawing.Imaging.ImageFormat(new Guid());
83.
84. //this.DrawImageFromFlashUploader(50, 50, rgbArray).Save(str, System.Drawing.Imaging.ImageFormat.Gif);
85.
86. //byte[] byteArray = new byte[str.Length];
87.
88. //int iii = str.Read(byteArray, 0, (int)str.Length);
89.
90. //Response.BinaryWrite(byteArray);
91.
92. //Response.Write("aaaaaa");
93.
94. //Response.End();
95.
96. //Page.RegisterStartupScript
97.
98. }
99.
100. }
101.
102.
103.
104. public System.Drawing.Bitmap DrawImageFromFlashUploader(int width, int height, string[] rgbArray)
105.
106. {
107.
108. System.Drawing.Bitmap bm = new System.Drawing.Bitmap(width, height,
System.Drawing.Imaging.PixelFormat.Format32bppRgb);
109.
110. int pos = 0;
111.
112. for (int i = bm.Height - 1; i >= 0; i--)
113.
114. {
115.
116. for (int j = 0; j < bm.Width; j++)
117.
118. {
119.
120. bm.SetPixel(j, i, System.Drawing.Color.FromArgb(int.Parse(rgbArray[pos], System.Globalization.NumberStyles.HexNumber)));
121.
122. pos++;
123.
124. }
125.
126. }
127.
128.
129.
130. return bm;
131.
132. }
133.
134. }
135.
136. }
137. </pre>
138. <pre class="csharp" name="code">我其实想做得更好看的,但我对flash不熟,只能实现个大概, 估计之后要做得更好还是要我来做,挺烦人的
139. </pre>

视频教程列表
文章教程搜索
 
Flash AS推荐教程
Flash AS热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058