/// <summary> /// 指定IPアドレスのカメラの撮影画像を取得する /// (先に SendCommandToGetFullImageInJpeg()で全ラズパイカメラに撮影命令を送信しておく ) /// throws IOException /// </summary> /// <param name="ipAddress"></param> /// <param name="portNo"></param> /// <returns></returns> public static byte[] GetFullImageInJpeg(string ipAddress, out int portNo) { byte[] imageData = null; // ポート番号を、IPアドレスの第4オクテットの数値によって SHOOTIMAGESERVER_PORT_NUM の範囲で変更する int idx = ipAddress.LastIndexOf('.'); int adrs4th = int.Parse(ipAddress.Substring(idx + 1)); int offset = adrs4th % SHOOTIMAGESERVER_PORT_NUM; portNo = SHOOTIMAGESERVER_PORT + offset; //System.Diagnostics.Debug.WriteLine( "{0}", portNo ); while (true) { var receiver = new AsyncImageReceiver(); imageData = receiver.ReceiveImage(ipAddress, portNo); if (imageData != null) { break; } else { // 画像データを受信できなかった場合はポート番号を変えて再試行 offset = (++offset) % SHOOTIMAGESERVER_PORT_NUM; portNo = SHOOTIMAGESERVER_PORT + offset; System.Diagnostics.Debug.WriteLine(" -> {0}:{1}", ipAddress, portNo); } } return(imageData); }
/// <summary> /// 指定IPアドレスのカメラの撮影画像を取得する /// (先に SendCommandToGetFullImageInJpeg()で全ラズパイカメラに撮影命令を送信しておく ) /// throws IOException /// </summary> /// <param name="ipAddress"></param> /// <param name="portNo"></param> /// <returns></returns> public static byte[] GetFullImageInJpeg(string ipAddress, out int portNo) { byte[] imageData = null; portNo = SHOOTIMAGESERVER_PORT; int offset = 0; while (true) { var receiver = new AsyncImageReceiver(); imageData = receiver.ReceiveImage(ipAddress, portNo); if (imageData != null) { break; } else { // 画像データを受信できなかった場合はポート番号を変えて再試行 offset = (++offset) % SHOOTIMAGESERVER_PORT_NUM; portNo = SHOOTIMAGESERVER_PORT + offset; System.Diagnostics.Debug.WriteLine(" -> {0}:{1}", ipAddress, portNo); } } return(imageData); }