无法弄清楚如何将1.2MB帧转换为字节[],以将相机帧从Windows 10 UWP C#应用程序发送到Xamarin iPad应用程序的套接字。
从相机到达镜框的事件...
private void Reader_FrameArrived( MediaFrameReader sender, MediaFrameArrivedEventArgs args )
{
using( MediaFrameReference frame = sender.TryAcquireLatestFrame() )
{
if( frame != null )
{
// frame = latest frame or null if no frame
var frame_size_bytes = frame.BufferMediaFrame.Buffer.Length;
if( SDKTemplate.SOURCE.Camera_Service_Socket.connection_established && frame != null )
{
//////////////////////////////// S E N D F R A M E T O I P A D /////////////////////////////
// Init packet header:
this.packet_header.CFV = 1;
var header_size_bytes = System.Runtime.InteropServices.Marshal.SizeOf(typeof( Packet_Header_struct));
this.packet_header.frame_size_bytes = Convert.ToInt32( frame_size_bytes );
this.packet_header.packet_sequence_index = packet_sequence_index++;
this.packet_header.ORC = 0; // TBD
this.packet_header.recognition_probability_factor = 0; // tbd
this.packet_header.logical_CRC = 0; // TBD
// Send packet header to iPad:
// Copy structure to a Byte array:
Byte[] header_buffer = getBytes( this.packet_header );
SDKTemplate.SOURCE.Camera_Service_Socket.send_data( header_buffer ); ///////// SEND 32 BYTE HEADER
// Send packet payload (ie. frame) to iPad:
// Copy
SDKTemplate.SOURCE.Camera_Service_Socket.send_data( frame.???????????????????? ); //////////// SEND 1.2MByte frame
}
// Display locally:
_frameRenderer.ProcessFrame( frame );
}
}
}
答案 0 :(得分:0)
如何将1.2MB帧转换为字节[]
您可以从帧的BufferMediaFrame中获取Buffer。然后,您可以调用.ToArray()方法来获取字节数组。
using (var frame = sender.TryAcquireLatestFrame())
{
if (frame != null)
{
IBuffer buffrer = frame.BufferMediaFrame.Buffer;
byte[] bytes = buffrer.ToArray();
}
_frameRenderer.ProcessFrame(frame);
}