Example #1
0
        public Control GetView(RageLib.FileSystem.Common.File file)
        {
            var data = file.GetData();

            var ms          = new MemoryStream(data);
            var textureFile = new TextureFile();

            try
            {
                textureFile.Open(ms);
            }
            finally
            {
                ms.Close();
            }

            var view       = new TexturePreviewView();
            var controller = new TexturePreviewController(view);

            controller.TextureFile = textureFile;

            return(view);
        }
        void DisplayTexture(TexureType type, string path)
        {
            try
            {
                var img    = LoadTextureAsTexture2d(path);
                var wpfImg = ImageToBitmap(img);
                var ff     = BitmapToImageSource(wpfImg);
                TexturePreviewView view = new TexturePreviewView();
                var dataContext         = new TexturePreviewViewModel()
                {
                    Format = "DDS0",
                    Name   = "MyTestImage.png",
                    Height = 512,
                    Width  = 1024
                };
                view.DataContext = dataContext;
                var w = new Window();

                w.Title = "Texture Preview Window";

                /*var bitmap = new Bitmap(dataContext.Width, dataContext.Height);
                 * using (Graphics gfx = Graphics.FromImage(bitmap))
                 * using (SolidBrush brush = new SolidBrush(System.Drawing.Color.FromArgb(255, 0, 0)))
                 * {
                 *  gfx.FillRectangle(brush, 0, 0, dataContext.Width, dataContext.Height);
                 * }*/
                dataContext.Image = ff;
                w.Content         = view;
                w.ShowDialog();
            }
            catch (Exception e)
            {
            }
            return;

            /*Texture2D t = _resourceLibary.LoadTexture(path, null);
             * Microsoft.Xna.Framework.Color[] colorArray = new Microsoft.Xna.Framework.Color[t.Width * t.Height];
             * try
             * {
             *   t.GetData(0, new Microsoft.Xna.Framework.Rectangle(0,0, t.Width, t.Height), colorArray, 0, t.Width * t.Height);
             * }
             * catch (Exception e)
             * { }*/

            return;

            /* TexturePreviewView view = new TexturePreviewView();
             * var dataContext = new TexturePreviewViewModel()
             * {
             *   Format = "DDS0",
             *   Name = "MyTestImage.png",
             *   Height = 512,
             *   Width = 1024
             * };
             * view.DataContext = dataContext;
             * var w = new Window();
             * w.Title = "Texture Preview Window";
             *
             * var bitmap = new Bitmap(dataContext.Width, dataContext.Height);
             * using (Graphics gfx = Graphics.FromImage(bitmap))
             * using (SolidBrush brush = new SolidBrush(System.Drawing.Color.FromArgb(255, 0, 0)))
             * {
             *   gfx.FillRectangle(brush, 0, 0, dataContext.Width, dataContext.Height);
             * }
             * dataContext.Image = BitmapToImageSource(bitmap);
             * w.Content = view;
             * w.ShowDialog();*/
        }