/// <summary>
        /// Updates the displayed image
        /// </summary>
        /// <remarks>
        /// This is called when an image has either been imported or enabled/disabled
        /// </remarks>
        /// <param name="offset">The new offset for the image.</param>
        /// <param name="isColor">Is the image being udpated a color set.</param>
        public void UpdateImage(int offset, bool isColor)
        {
            if (isColor)
            {
                var colorBMP = MTRL.GetColorBitmap(offset);

                TextureType       = "A16B16G16R16F";
                TextureDimensions = "(4 x 16)";

                alphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(colorBMP.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

                var removeAlphaBitmap = SetAlpha(colorBMP, 255);

                noAlphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(removeAlphaBitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

                colorBMP.Dispose();
                removeAlphaBitmap.Dispose();
            }
            else
            {
                if (SelectedMap.ID.Contains("vfx"))
                {
                    texData = TEX.GetVFX(offset);
                }
                else
                {
                    texData = TEX.GetTex(offset);
                }

                TextureType       = texData.TypeString;
                TextureDimensions = "(" + texData.Width + " x " + texData.Height + ")";

                alphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(texData.BMP.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

                var removeAlphaBitmap = SetAlpha(texData.BMP, 255);

                noAlphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(removeAlphaBitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

                texData.Dispose();
                removeAlphaBitmap.Dispose();
            }

            if (AlphaChecked)
            {
                ImageSource = alphaBitmap;
            }
            else
            {
                ImageSource = noAlphaBitmap;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Updates the displayed image
        /// </summary>
        /// <remarks>
        /// This is called when an image has either been imported or enabled/disabled
        /// </remarks>
        /// <param name="offset">The new offset for the image.</param>
        /// <param name="isColor">Is the image being udpated a color set.</param>
        public void UpdateImage(int offset, bool isColor)
        {
            try
            {
                if (isColor)
                {
                    var colorBMP = MTRL.GetColorBitmap(offset);

                    TextureType       = "Type: 16.16.16.16f ABGR\nMipMaps: 0";
                    TextureDimensions = "(4 x 16)";

                    alphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(colorBMP.Item1.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                    alphaBitmap.Freeze();

                    var removeAlphaBitmap = SetAlpha(colorBMP.Item1, 255);

                    noAlphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(removeAlphaBitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                    noAlphaBitmap.Freeze();

                    mtrlData.ColorData = colorBMP.Item2;

                    colorBMP.Item1.Dispose();
                    removeAlphaBitmap.Dispose();
                }
                else
                {
                    if (SelectedMap.ID.Contains("vfx"))
                    {
                        texData = TEX.GetVFX(offset, Strings.ItemsDat);
                    }
                    else
                    {
                        if (selectedCategory.Equals("UI"))
                        {
                            texData = TEX.GetTex(offset, Strings.UIDat);
                        }
                        else
                        {
                            texData = TEX.GetTex(offset, Strings.ItemsDat);
                        }
                    }

                    string mipMaps = "Yes (" + texData.MipCount + ")";
                    if (texData.MipCount < 1)
                    {
                        mipMaps = "None";
                    }
                    TextureType       = "Type: " + texData.TypeString + "\nMipMaps: " + mipMaps;
                    TextureDimensions = "(" + texData.Width + " x " + texData.Height + ")";

                    alphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(texData.BMP.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

                    var removeAlphaBitmap = SetAlpha(texData.BMP, 255);

                    noAlphaBitmap = Imaging.CreateBitmapSourceFromHBitmap(removeAlphaBitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

                    texData.Dispose();
                    removeAlphaBitmap.Dispose();
                }

                if (AlphaChecked)
                {
                    ImageSource = alphaBitmap;
                }
                else
                {
                    ImageSource = noAlphaBitmap;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("[TVM] There was an error updating the image.\n" + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }