Ejemplo n.º 1
0
        public static Image ImageFromFile(string filePath)
        {
            uint imageID = 0;

            DevILMethods.ilGenImages(1, ref imageID);
            DevILMethods.ilBindImage(imageID);

            if (DevILMethods.ilLoadImage(filePath) != 0)
            {
                uint   width    = DevILMethods.ilGetInteger(DevILMethods.IL_IMAGE_WIDTH);
                uint   height   = DevILMethods.ilGetInteger(DevILMethods.IL_IMAGE_HEIGHT);
                uint   depth    = DevILMethods.ilGetInteger(DevILMethods.IL_IMAGE_DEPTH);
                Bitmap original = new Bitmap((int)width, (int)height, PixelFormat.Format32bppArgb);

                Rectangle  rect    = new Rectangle(0, 0, (int)width, (int)height);
                BitmapData bmpData = original.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

                DevILMethods.ilConvertImage(DevILMethods.IL_BGRA, DevILMethods.IL_UNSIGNED_BYTE);
                DevILMethods.ilCopyPixels(0, 0, 0, width, height, 1, DevILMethods.IL_BGRA, DevILMethods.IL_UNSIGNED_BYTE, bmpData.Scan0);

                original.UnlockBits(bmpData);

                DevILMethods.ilDeleteImages(1, ref imageID);
                if (original != null)
                {
                    return(original);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        private void AddTextureItem(string category, string itemName, string variableName, string fileName)
        {
            Image original = DevILMethods.ImageFromFile(fileName);

            if (original != null)
            {
                original = DevILMethods.FixedSize(original, 20, 20);
            }
            Inspector.ImageItem imageItem = new Inspector.ImageItem(category, itemName, variableName, fileName, original);
            imageItem.ValueChanging += ImageItem_ValueChanging;
            inspectorComponent.ItemAdd(imageItem);
        }
Ejemplo n.º 3
0
 public PropertiesView()
 {
     InitializeComponent();
     try
     {
         DevILMethods.ilInit();
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }
Ejemplo n.º 4
0
        private void ImageItem_ValueChanging(object sender, string value)
        {
            TexturesDialog dialog = new TexturesDialog();

            dialog.FileName         = value;
            dialog.TextureDirectory = m_ProjectLocation + @"\Textures";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                Inspector.ImageItem imageItem = sender as Inspector.ImageItem;
                m_ModifyDelegate?.Invoke(imageItem.VariableName, Path.GetFileName(dialog.FileName));
                imageItem.FileName = dialog.FileName;
                Image original = DevILMethods.ImageFromFile(dialog.FileName);
                if (original != null)
                {
                    original = DevILMethods.FixedSize(original, 20, 20);
                }
                imageItem.Value = original;
            }
        }
Ejemplo n.º 5
0
        private void AddNewImage(string filePath)
        {
            ListViewItem item = new ListViewItem();

            item.Text        = Path.GetFileName(filePath);
            item.ToolTipText = filePath;
            listViewTextures.Items.Add(item);

            bool success = false;

            try
            {
                Image original = Image.FromFile(filePath);
                if (original != null)
                {
                    imageListLarge.Images.Add(DevILMethods.FixedSize(original, imageListLarge.ImageSize.Width, imageListLarge.ImageSize.Height));
                    item.ImageIndex = imageListLarge.Images.Count - 1;
                    success         = true;
                }
            }
            catch (OutOfMemoryException)
            {
            }

            if (!success)
            {
                Image original = DevILMethods.ImageFromFile(filePath);
                if (original != null)
                {
                    imageListLarge.Images.Add(DevILMethods.FixedSize(original, imageListLarge.ImageSize.Width, imageListLarge.ImageSize.Height));
                    item.ImageIndex = imageListLarge.Images.Count - 1;
                }
                else
                {
                    item.ImageIndex = 0;
                }
            }
        }