まず、画像の転送バイト
公共の バイト[] ImageToByte() { 文字列画像ファイル= @ " http://192.168.0.212/pass/T-1.jpg "。// 互联网图片地址 画像IMG = UrlToImage(画像ファイル)。 ビットマップBMP = 新しいビットマップ(IMG); MemoryStreamをミリ秒 = 新規のMemoryStream()。 bmp.Save(MS、System.Drawing.Imaging.ImageFormat.Jpeg)。 バイト [] ARR = 新しい バイト[ms.Length]。 ms.Position = 0 ; ms.Read(ARR、0、(int型)ms.Length)。 ms.Close(); VaRの A = Convert.ToBase64String(ARR)。 文字列 strbaser64 = "" ; Webクライアントのmywebclient = 新しいWebクライアント(); バイト []バイト= mywebclient.DownloadData(画像ファイル)。 戻りバイト } 公共 イメージUrlToImage(文字列URL) { Webクライアントmywebclient = 新しいWebクライアント()。 バイト []バイト= mywebclient.DownloadData(URL)。 使用(MemoryStreamをミリ秒= 新規のMemoryStream(バイト)) { イメージoutputImg = Image.FromStream(ミリ秒)。 返すoutputImg; } }
二、バイト転送の写真
:画像へのバイト配列保存 モード1:System.IO.File.WriteAllBytes("@ :\ test.jpg C " ;、バイト) 第二の方法:MSのMemoryStream = 新しい新しいのMemoryStream(バイト[] B)を、バイトを入れて[ ]配列に渡し、その後 のFileStream FS = 新しい新規のFileStream(例えばパス:" E:\画像\の1.JPG " ); ms.writeto(FS); ms.close(); fs.Close() メソッド3: / / 画像アドレス取得 VARを(stringFilePath context.Server.MapPath = ストリング .Format(" 〜/画像/ {{0}} 1 .JPG " 、imagenameの、ID)); // のFileStreamに一時的にするための画像を宣言するストリーム ストリーム= FileStreamを新しい新規のFileStream(stringFilePath、FileMode.Open); 使用(ストリーム) { // GetImageFromStream方法写真を介してバイト配列に バイト [] =のimageBytes この.GetImageFromStream(ストリーム、コンテキスト); // コンテキスト決意書き込みクライアントのショートへのファイルの種類 context.Response.ContentType = " 画像/ JPEG " ; // 前のimageBytesで書かれたコンテキストデータ context.Response.BinaryWrite(imageBytes); stream.Close(); }