There are two class MainPage and Callback. I used C++ library, so I get byte array via CLI. When I get data callback class, I want pass the data callback class to MainPage class(It's UI thread). Finally, I want to draw Image after getting byte array.
<Image x:Name="ImageScreen" x:FieldModifier="public" Height="357" Width="456" Margin="0,33,0,201"/>
== MainPage.xaml.cs ==
public class Callback : ComponentCallback
{
static byte[] byteArray;
...
// I get data via this function. When I get the data,
// I want to pass the data to updateImage function in MainPage class.
public void onFrameLoaded(int camera, String title, UInt32 bufferSize)
{
System.Collections.Generic.List<byte> buffer = MainPage._watcher.getBuffer().ToList();
byteArray = buffer.ToArray();
// I want pass byteArray to updateImage.
}
}
public partial class MainPage : PhoneApplicationPage
{
public static Component _watcher;
public static Callback _watcherCallback;
public MainPage()
{
InitializeComponent();
CoreComponent _core = new CoreComponent();
int fenport = _core.fenServerPort();
_core.setFenServer("", );
fenport = _core.fenServerPort();
_watcher = new Component();
_watcherCallback = new Callback();
_watcher.setCallback(_watcherCallback);
_watcher.connect(0, "", 0, "", "");
}
public void updateImage(byte[] byteArray)
{
BitmapImage bi = new BitmapImage();
MemoryStream stream = new MemoryStream(byteArray);
bi.SetSource(stream);
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
//Update the UI controls here
ImageScreen.Source = bi;
});
}
}
var frame = Window.Current as Frame;
if (frame == null)
{
return; //?
}
var mainPage = frame.Content as MainPage;
if (mainPage == null)
{
return; //?
}
mainPage.updateImage(byteArray);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments