0

Cannot add image annotation in Windows Phone 8.1.

PPanda Piriya 9 years ago 0
Hi,
I'm working on WP8.1 project with MvvmCross - Hot Tuna v3.5.0 and MvvmCross Resource Loader Plugin v3.5.0 on Visual Studio 2013 Update 4.
I have a problem with Image Annotation. For the scenario, after check box is checked, graph adds vertical line with image next to the line. In this case, the line works fine but the image makes the app freezing.
The following code is my demo project to check that the Image Annotation works properly or my code breaks it. This example adds image directly to the graph. However, I encounter the same problem.

FirstViewModel.cs:
public class FirstViewModel
: MvxViewModel
{
public PlotModel PlotModel { get; private set; }
private Dictionary<string, OxyImage> _annotationImages;

public FirstViewModel(IMvxResourceLoader resourceLoader)
{
var model = new PlotModel { Title = "Hello Windows" };
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom });
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
var lineSeries = new LineSeries { Title = "LineSeries", MarkerType = MarkerType.Circle };
lineSeries.Points.Add(new DataPoint(0, 0));
lineSeries.Points.Add(new DataPoint(10, 18));
lineSeries.Points.Add(new DataPoint(20, 12));
lineSeries.Points.Add(new DataPoint(30, 8));
lineSeries.Points.Add(new DataPoint(40, 15));

OxyImage image = null;
try
{
resourceLoader.GetResourceStream(imageFileName, (stream) =>
{
image = new OxyImage(stream);
});
}
catch (Exception ex)
{
Mvx.TaggedError("RotavaporPlotModel", "Failed to load image for annotation: {0}", ex);
}

var imageAnnotation = new ImageAnnotation()
{
ImageSource = image,
Opacity = 0.2,
Interpolate = false,
X = new PlotLength(0.5, PlotLengthUnit.RelativeToPlotArea),
Y = new PlotLength(0.5, PlotLengthUnit.RelativeToPlotArea),
Width = new PlotLength(1, PlotLengthUnit.RelativeToPlotArea),
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Middle
};
model.Annotations.Add(imageAnnotation);

model.Series.Add(lineSeries);
this.PlotModel = model;
}
}

FirstView.xaml:
<views:MvxWindowsPage
x:Class="OxyPlotDemo.Phone.Views.FirstView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:oxy="using:OxyPlot.Windows"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:views="using:Cirrious.MvvmCross.WindowsCommon.Views"
mc:Ignorable="d">

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<oxy:PlotView Model="{Binding PlotModel}"/>
</Grid>
</views:MvxWindowsPage>

FirstView.xaml.cs:
using Cirrious.MvvmCross.WindowsCommon.Views;
namespace OxyPlotDemo.Phone.Views
{
public sealed partial class FirstView : MvxWindowsPage
{
public FirstView()
{
this.InitializeComponent();
}
}
}

The following lines are stack trace after I run this code (these are done in WorkerThread):
mscorlib.ni.dll!System.Threading.Monitor.Wait(object obj, int millisecondsTimeout, bool exitContext)
mscorlib.ni.dll!System.Threading.Monitor.Wait(object obj, int millisecondsTimeout)
mscorlib.ni.dll!System.Threading.ManualResetEventSlim.Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken)
mscorlib.ni.dll!System.Threading.Tasks.Task.SpinThenBlockingWait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken)
mscorlib.ni.dll!System.Threading.Tasks.Task.InternalWait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken)
mscorlib.ni.dll!System.Threading.Tasks.Task<Windows.Storage.Streams.IRandomAccessStream>.GetResultCore(bool waitCompletionNotification)
mscorlib.ni.dll!System.Threading.Tasks.Task<System.__Canon>.Result.get()
OxyPlot.Windows.DLL!OxyPlot.Windows.RenderContext.GetImageSource(OxyPlot.OxyImage image)
OxyPlot.Windows.DLL!OxyPlot.Windows.RenderContext.DrawImage(OxyPlot.OxyImage source, double srcX, double srcY, double srcWidth, double srcHeight, double destX, double destY, double destWidth, double destHeight, double opacity, bool interpolate)
OxyPlot.DLL!OxyPlot.RenderingExtensions.DrawImage(OxyPlot.IRenderContext rc, OxyPlot.OxyImage image, double x, double y, double w, double h, double opacity, bool interpolate)
OxyPlot.DLL!OxyPlot.Annotations.ImageAnnotation.Render(OxyPlot.IRenderContext rc)
OxyPlot.DLL!OxyPlot.PlotModel.RenderAnnotations(OxyPlot.IRenderContext rc, OxyPlot.Annotations.AnnotationLayer layer)
OxyPlot.DLL!OxyPlot.PlotModel.RenderOverride(OxyPlot.IRenderContext rc, double width, double height)
OxyPlot.DLL!OxyPlot.PlotModel.OxyPlot.IPlotModel.Render(OxyPlot.IRenderContext rc, double width, double height)
OxyPlot.Windows.DLL!OxyPlot.Windows.PlotView.UpdateVisuals()
OxyPlot.Windows.DLL!OxyPlot.Windows.PlotView.ArrangeOverride(Windows.Foundation.Size finalSize)

Then I try to run example project which I get from GitHub. Example project version is 0.0.1.0.
I got the following stack trace:

mscorlib.ni.dll!System.Threading.Monitor.Wait(object obj, int millisecondsTimeout, bool exitContext)
mscorlib.ni.dll!System.Threading.Monitor.Wait(object obj, int millisecondsTimeout)
mscorlib.ni.dll!System.Threading.ManualResetEventSlim.Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken)
mscorlib.ni.dll!System.Threading.Tasks.Task.SpinThenBlockingWait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken)
mscorlib.ni.dll!System.Threading.Tasks.Task.InternalWait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken)
mscorlib.ni.dll!System.Threading.Tasks.Task<Windows.Storage.Streams.IRandomAccessStream>.GetResultCore(bool waitCompletionNotification)
mscorlib.ni.dll!System.Threading.Tasks.Task<System.__Canon>.Result.get()
OxyPlot.Windows.DLL!OxyPlot.Windows.RenderContext.GetImageSource(OxyPlot.OxyImage image) Line 793
OxyPlot.Windows.DLL!OxyPlot.Windows.RenderContext.DrawImage(OxyPlot.OxyImage source, double srcX, double srcY, double srcWidth, double srcHeight, double destX, double destY, double destWidth, double destHeight, double opacity, bool interpolate) Line 571
> OxyPlot.DLL!OxyPlot.RenderingExtensions.DrawImage(OxyPlot.IRenderContext rc, OxyPlot.OxyImage image, double x, double y, double w, double h, double opacity, bool interpolate) Line 239
OxyPlot.DLL!OxyPlot.Annotations.ImageAnnotation.Render(OxyPlot.IRenderContext rc) Line 176
OxyPlot.DLL!OxyPlot.PlotModel.RenderAnnotations(OxyPlot.IRenderContext rc, OxyPlot.Annotations.AnnotationLayer layer) Line 346
OxyPlot.DLL!OxyPlot.PlotModel.RenderOverride(OxyPlot.IRenderContext rc, double width, double height) Line 109
OxyPlot.DLL!OxyPlot.PlotModel.OxyPlot.IPlotModel.Render(OxyPlot.IRenderContext rc, double width, double height) Line 32
OxyPlot.Windows.DLL!OxyPlot.Windows.PlotView.UpdateVisuals() Line 897
OxyPlot.Windows.DLL!OxyPlot.Windows.PlotView.ArrangeOverride(Windows.Foundation.Size finalSize) Line 793

Could you please help me with this? Am I do anything wrong or it is a bug here?
Thank you in advance for your feedback.

Cheers,
Peerapon P.