private void ShowImage(byte[] image)
{
try
{
MemoryStream ms = new MemoryStream(image);
BitmapDecoder decoder = null;
MAVLink.MAVLINK_DATA_STREAM_TYPE type = (MAVLink.MAVLINK_DATA_STREAM_TYPE)incoming_image.type;
switch (type)
{
case MAVLink.MAVLINK_DATA_STREAM_TYPE.MAVLINK_DATA_STREAM_IMG_JPEG:
decoder = JpegBitmapDecoder.Create(ms, BitmapCreateOptions.IgnoreImageCache, BitmapCacheOption.None);
break;
case MAVLink.MAVLINK_DATA_STREAM_TYPE.MAVLINK_DATA_STREAM_IMG_BMP:
decoder = BitmapDecoder.Create(ms, BitmapCreateOptions.IgnoreImageCache, BitmapCacheOption.None);
break;
case MAVLink.MAVLINK_DATA_STREAM_TYPE.MAVLINK_DATA_STREAM_IMG_RAW8U:
var raw = Raw8UBitmapDecoder.Create(image, incoming_image.width, incoming_image.height);
BitmapFrame frame = raw.Frames[0];
ImageViewer.Source = frame;
break;
case MAVLink.MAVLINK_DATA_STREAM_TYPE.MAVLINK_DATA_STREAM_IMG_RAW32U:
//decoder = Raw8UBitmapDecoder.Create(ms, incoming_image.width, incoming_image.height);
break;
case MAVLink.MAVLINK_DATA_STREAM_TYPE.MAVLINK_DATA_STREAM_IMG_PGM:
//decoder = PgmBitmapDecoder.Create(ms, BitmapCreateOptions.IgnoreImageCache, BitmapCacheOption.None);
break;
case MAVLink.MAVLINK_DATA_STREAM_TYPE.MAVLINK_DATA_STREAM_IMG_PNG:
decoder = PngBitmapDecoder.Create(ms, BitmapCreateOptions.IgnoreImageCache, BitmapCacheOption.None);
break;
}
if (decoder != null && decoder.Frames.Count > 0)
{
BitmapFrame frame = decoder.Frames[0];
ImageViewer.Source = frame;
}
}
catch
{
}
}