public void DrawPicture(int picture, byte[] Image, int y, int x)
        {
            Dispatcher.Invoke(new Action(delegate
            {
                // If the image would go beyond the actual bounds of the display, don't bother drawing it.
                if (x > this.ActualWidth || y > this.ActualHeight) return;

                byte[] buffer = Image;

                if (os_._blorbFile.AdaptivePalatte != null && os_._blorbFile.AdaptivePalatte.Count > 0)
                {

                    try
                    {
                        // Had to use the adaptive palatte for some Infocom games
                        var ms = new System.IO.MemoryStream(Image);
                        FrotzNetDLL.Frotz.Other.PNG p = new FrotzNetDLL.Frotz.Other.PNG(ms);


                        if (os_._blorbFile.AdaptivePalatte.Contains(picture))
                        {
                            if (_palatteChunk == null) throw new ArgumentException("No last palette");
                            p.Chunks["PLTE"] = _palatteChunk;
                        }
                        else
                        {
                            _palatteChunk = p.Chunks["PLTE"];
                        }

                        ms = new System.IO.MemoryStream();
                        p.Save(ms);

                        buffer = ms.ToArray();
                    }
                    catch (ArgumentException)
                    {
                        // TODO It's bad form to not at least define the exception better
                    }
                }


                FrotzImage img = new FrotzImage();
                BitmapImage bi = new BitmapImage();
                bi.BeginInit();
                bi.StreamSource = new System.IO.MemoryStream(buffer);

                bi.EndInit();
                img.Source = bi;

                RenderOptions.SetBitmapScalingMode(img, BitmapScalingMode.NearestNeighbor);

                int newX = x;
                int newY = y;

                if (newY > short.MaxValue) newY -= ushort.MaxValue;
                if (newX > short.MaxValue) newX -= ushort.MaxValue;

                img.SetValue(Canvas.TopProperty, (double)newY);
                img.SetValue(Canvas.LeftProperty, (double)newX);

                img.SetValue(Canvas.HeightProperty, (double)(bi.Height * scale));
                img.SetValue(Canvas.WidthProperty, (double)(bi.Width * scale));

                if (picture == 1)
                {
                    if (img.Source.Width > mainCanvas.ActualWidth || img.Source.Height > mainCanvas.ActualHeight)
                    {
                        // Picture one is generallythe title page, Resize the img to be the same size as the canvas, 
                        // and it will show correctly in the bounds
                        img.SetValue(Canvas.WidthProperty, mainCanvas.ActualWidth);
                        img.SetValue(Canvas.HeightProperty, mainCanvas.ActualHeight);
                    }
                }

                mainCanvas.Children.Add(img);

                // removeCoveredImages(img);
            }));
        }
        public void DrawPicture(int picture, byte[] Image, int y, int x)
        {
            Dispatcher.Invoke(new Action(delegate
            {
                // If the image would go beyond the actual bounds of the display, don't bother drawing it.
                if (x > this.ActualWidth || y > this.ActualHeight)
                {
                    return;
                }

                byte[] buffer = Image;

                if (os_._blorbFile.AdaptivePalatte != null && os_._blorbFile.AdaptivePalatte.Count > 0)
                {
                    try
                    {
                        // Had to use the adaptive palatte for some Infocom games
                        var ms = new System.IO.MemoryStream(Image);
                        FrotzNetDLL.Frotz.Other.PNG p = new FrotzNetDLL.Frotz.Other.PNG(ms);


                        if (os_._blorbFile.AdaptivePalatte.Contains(picture))
                        {
                            if (_palatteChunk == null)
                            {
                                throw new ArgumentException("No last palette");
                            }
                            p.Chunks["PLTE"] = _palatteChunk;
                        }
                        else
                        {
                            _palatteChunk = p.Chunks["PLTE"];
                        }

                        ms = new System.IO.MemoryStream();
                        p.Save(ms);

                        buffer = ms.ToArray();
                    }
                    catch (ArgumentException)
                    {
                        // TODO It's bad form to not at least define the exception better
                    }
                }


                FrotzImage img = new FrotzImage();
                BitmapImage bi = new BitmapImage();
                bi.BeginInit();
                bi.StreamSource = new System.IO.MemoryStream(buffer);

                bi.EndInit();
                img.Source = bi;

                RenderOptions.SetBitmapScalingMode(img, BitmapScalingMode.NearestNeighbor);

                int newX = x;
                int newY = y;

                if (newY > short.MaxValue)
                {
                    newY -= ushort.MaxValue;
                }
                if (newX > short.MaxValue)
                {
                    newX -= ushort.MaxValue;
                }

                img.SetValue(Canvas.TopProperty, (double)newY);
                img.SetValue(Canvas.LeftProperty, (double)newX);

                img.SetValue(Canvas.HeightProperty, (double)(bi.Height * scale));
                img.SetValue(Canvas.WidthProperty, (double)(bi.Width * scale));

                if (picture == 1)
                {
                    if (img.Source.Width > mainCanvas.ActualWidth || img.Source.Height > mainCanvas.ActualHeight)
                    {
                        // Picture one is generallythe title page, Resize the img to be the same size as the canvas,
                        // and it will show correctly in the bounds
                        img.SetValue(Canvas.WidthProperty, mainCanvas.ActualWidth);
                        img.SetValue(Canvas.HeightProperty, mainCanvas.ActualHeight);
                    }
                }

                mainCanvas.Children.Add(img);

                // removeCoveredImages(img);
            }));
        }