This article is Frank's learning notes. For more information, see the original article link. In C #, the stream sent by post and byte Arrays' operations seem to contain very few data files. below is my research result over the past few days. The function is to copy a.jpg under the same file to generate B .jpg.CodeAs follows: Bytearray. aspx. CS Using system; Using system. IO; Using system. Data; Using system. drawing; Using system. Drawing. imaging; Using system. net; /*@ Author: Frank Site: www.2solo.cn Date: 2008.02.20 Info: C # copy the image, stream and bytearray application, and generate the image part */ Namespace barray { Public partial class imghandler: system. Web. UI. Page { Protected void page_load (Object sender, eventargs E) { Try { Stream sin = page. Request. inputstream; System. Drawing. Image IMG = system. Drawing. bitmap. fromstream (SIN ); Bitmap BMP = new Bitmap (IMG ); Memorystream BMP stream = new memorystream (); BMP. Save (BMP stream, system. Drawing. imaging. imageformat. JPEG ); Filestream FS = new filestream (system. Web. httpcontext. Current. server. mappath ("B .jpg"), filemode. Create ); BMP stream. writeto (FS ); BMP stream. Close (); FS. Close (); BMP stream. Dispose (); FS. Dispose (); Response. Write ("successful "); } Catch { Response. Write ("failed "); } } } } Gopost. aspx. CS Using system; Using system. IO; Using system. drawing; Using system. Drawing. imaging; Using system. net; Using system. text; /*@ Author: Frank Site: www.2solo.cn Date: 2008.02.20 Info: C # copy the image, stream and bytearray application, and submit the image Section */ Namespace gopost { Public partial class posthandler: system. Web. UI. Page { Protected void page_load (Object sender, eventargs E) { Postimage (); } Private void postimage () { Try { Httpwebrequest request; String imgurl = system. Web. httpcontext. Current. server. mappath ("a.jpg "); Request = (httpwebrequest) httpwebrequest. Create (http: // localhost/bytearray. aspx ); Request. keepalive = true; Request. method = "Post "; Byte [] bytearray = cvtimgbarr (system. Drawing. Image) New Bitmap (@ imgurl), imageformat. JPEG ); Request. contenttype = "image/JPEG "; Request. contentlength = bytearray. length; Stream newstream = request. getrequeststream (); Newstream. Write (bytearray, 0, bytearray. Length ); Newstream. Close (); Response. Write ("image copied "); } Catch { Response. Write ("failed to copy the image "); } } Private Static byte [] cvtimgbarr (system. Drawing. Image imagetoconvert, imageformat formatofimage) { Byte [] imarr; Try { Using (memorystream myms = new memorystream ()) { Imagetoconvert. Save (myms, formatofimage ); Imarr = myms. toarray (); } } Catch (exception) {Throw ;} Return imarr; } } } Relatively speaking, the application of byte array in HTML forms may be ignored all the time, but correct application of byte array can be greatly optimized.ProgramAnd make some unexpected results. Of course, I studied byte array mainly for the recent flash research. Attached sample file: http://www.2solo.cn/upload/cbyteArray_2soloDOTcn.zip |